diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RestrictedGenericDAO.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RestrictedGenericDAO.java index cb1b731e..2dc720bd 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RestrictedGenericDAO.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/RestrictedGenericDAO.java @@ -27,7 +27,7 @@ public interface RestrictedGenericDAO /* extends GenericDAO search(Search search); public long count(Search search); diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java index d25ab45c..033d0e87 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/AdminRuleDAOImpl.java @@ -128,8 +128,8 @@ public AdminRule merge(AdminRule entity) { } @Override - public void remove(AdminRule entity) { - super.remove(entity); + public boolean remove(AdminRule entity) { + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/BaseDAO.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/BaseDAO.java index 3bb08c3c..a1b586f7 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/BaseDAO.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/BaseDAO.java @@ -100,8 +100,8 @@ public void merge(E... entities) { } } - public void remove(E entity) { - removeById(entity.getId()); + public boolean remove(E entity) { + return removeById(entity.getId()); } public boolean removeById(Long id) { diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java index 9e6f0b71..3c3103ce 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GFUserDAOImpl.java @@ -66,9 +66,9 @@ public GFUser merge(GFUser entity) } @Override - public void remove(GFUser entity) + public boolean remove(GFUser entity) { - super.remove(entity); + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java index f6dece43..bae1a881 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSInstanceDAOImpl.java @@ -57,9 +57,9 @@ public GSInstance merge(GSInstance entity) } @Override - public void remove(GSInstance entity) + public boolean remove(GSInstance entity) { - super.remove(entity); + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java index afe60931..bd6d0794 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/GSUserDAOImpl.java @@ -109,9 +109,9 @@ public GSUser merge(GSUser entity) } @Override - public void remove(GSUser entity) + public boolean remove(GSUser entity) { - super.remove(entity); + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java index 1cffd890..cf77f36a 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/LayerDetailsDAOImpl.java @@ -72,8 +72,8 @@ public LayerDetails merge(LayerDetails entity) { } @Override - public void remove(LayerDetails entity) { - super.remove(entity); + public boolean remove(LayerDetails entity) { + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java index b55a3e35..f89b0254 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleDAOImpl.java @@ -132,8 +132,8 @@ public Rule merge(Rule entity) { } @Override - public void remove(Rule entity) { - super.remove(entity); + public boolean remove(Rule entity) { + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java index 2ad78456..9fab4acd 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/RuleLimitsDAOImpl.java @@ -58,9 +58,9 @@ public RuleLimits merge(RuleLimits entity) } @Override - public void remove(RuleLimits entity) + public boolean remove(RuleLimits entity) { - super.remove(entity); + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java index fd809154..3e34f82d 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/impl/UserGroupDAOImpl.java @@ -65,9 +65,9 @@ public UserGroup merge(UserGroup entity) } @Override - public void remove(UserGroup entity) + public boolean remove(UserGroup entity) { - super.remove(entity); + return super.remove(entity); } @Override diff --git a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/search/Search.java b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/search/Search.java index aa715f54..ca762c9e 100644 --- a/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/search/Search.java +++ b/src/services/core/persistence/src/main/java/org/geoserver/geofence/core/dao/search/Search.java @@ -33,6 +33,7 @@ public class Search { Integer firstResult = null; Integer maxResults = null; + Integer page = null; protected Search(EntityManager em, Class resultType, Class rootClass) { this.em = em; @@ -72,8 +73,9 @@ public void setMaxResults(int i) { maxResults = i; } -// public void setPage(Integer page) { -// } + public void setPage(int page) { + this.page = page; + } public void addSortAsc(String field) { orderBy.add(cb.asc(root.get(field))); @@ -188,14 +190,24 @@ public TypedQuery getQuery() { TypedQuery query = em.createQuery(q); + applyPagination(query); + + return query; + } + + private void applyPagination(TypedQuery query) throws IllegalStateException { if(firstResult != null) { query.setFirstResult(firstResult); } if(maxResults != null) { query.setMaxResults(maxResults); } - - return query; + if(page != null) { + if(maxResults == null) { + throw new IllegalStateException("Page set without maxresults"); + } + query.setFirstResult((page-1) * maxResults); + } } // public TypedQuery _getCountQuery() { diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java index 2d1a05c3..95415b24 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AdminRuleAdminServiceImpl.java @@ -126,7 +126,7 @@ public void deleteRulesByUser(String username) throws NotFoundServiceEx { @Override public void deleteRulesByRole(String rolename) throws NotFoundServiceEx { Search searchCriteria = ruleDAO.createSearch(); - searchCriteria.addFilter(Filter.equal("rolename", rolename)); + searchCriteria.addFilterEqual("rolename", rolename); List list = ruleDAO.search(searchCriteria); for (AdminRule rule : list) { @@ -139,7 +139,7 @@ public void deleteRulesByRole(String rolename) throws NotFoundServiceEx { @Override public void deleteRulesByInstance(long instanceId) throws NotFoundServiceEx { Search searchCriteria = ruleDAO.createSearch(); - searchCriteria.addFilter(Filter.equal("instance.id", instanceId)); + searchCriteria.addFilterEqual("instance.id", instanceId); List list = ruleDAO.search(searchCriteria); for (AdminRule rule : list) { @@ -181,7 +181,7 @@ public ShortAdminRule getRule(RuleFilter filter) throws BadRequestServiceEx { @Override public List getRulesByPriority(long priority, Integer page, Integer entries) { Search searchCriteria = ruleDAO.createSearch(); - searchCriteria.addFilter(Filter.greaterOrEqual("priority", priority)); + searchCriteria.addFilterGreaterOrEqual("priority", priority); searchCriteria.addSortAsc("priority"); addPagingConstraints(searchCriteria, page, entries); List found = ruleDAO.search(searchCriteria); @@ -191,7 +191,7 @@ public List getRulesByPriority(long priority, Integer page, Inte @Override public ShortAdminRule getRuleByPriority(long priority) throws BadRequestServiceEx { Search searchCriteria = ruleDAO.createSearch(); - searchCriteria.addFilter(Filter.equal("priority", priority)); + searchCriteria.addFilterEqual("priority", priority); List found = ruleDAO.search(searchCriteria); if(found.isEmpty()) return null; @@ -211,7 +211,8 @@ public List getListFull(RuleFilter filter, Integer page, Integer entr } protected Search buildSearch(Integer page, Integer entries, RuleFilter filter) throws BadRequestServiceEx { - Search searchCriteria = buildRuleSearch(filter); + Search searchCriteria = ruleDAO.createSearch(); + searchCriteria = buildRuleSearch(searchCriteria, filter); addPagingConstraints(searchCriteria, page, entries); searchCriteria.addSortAsc("priority"); return searchCriteria; @@ -226,8 +227,8 @@ public long getCountAll() { public long count(RuleFilter filter) { // if(LOGGER.isDebugEnabled()) // LOGGER.debug("Counting rules: " + filter); - - Search searchCriteria = buildRuleSearch(filter); + Search searchCriteria = ruleDAO.createCountSearch(); + searchCriteria = buildRuleSearch(searchCriteria, filter); // if(LOGGER.isDebugEnabled()) // LOGGER.debug("Counting rules: " + searchCriteria); return ruleDAO.count(searchCriteria); @@ -236,8 +237,8 @@ public long count(RuleFilter filter) { // ========================================================================= // Search stuff - private Search buildRuleSearch(RuleFilter filter) { - Search searchCriteria = new Search(AdminRule.class); + private Search buildRuleSearch(Search searchCriteria, RuleFilter filter) { + if(filter != null) { addStringCriteria(searchCriteria, "username", filter.getUser()); @@ -255,7 +256,7 @@ private Search buildRuleSearch(RuleFilter filter) { //========================================================================= private Search buildFixedRuleSearch(RuleFilter filter) { - Search searchCriteria = new Search(AdminRule.class); + Search searchCriteria = ruleDAO.createSearch(); if(filter != null) { addFixedStringCriteria(searchCriteria, "username", filter.getUser()); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java index b27a1b86..52b7e64e 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/AuthorizationServiceImpl.java @@ -41,7 +41,7 @@ public AuthUser authorize(String username, String password) { } private GSUser getUserByName(String userName) { - Search search = new Search(GSUser.class); + Search search = userDAO.createSearch(); search.addFilterEqual("name", userName); List users = userDAO.search(search); if(users.size() > 1) diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java index 603542de..0bd44f38 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/GFUserAdminServiceImpl.java @@ -59,7 +59,7 @@ public GFUser get(long id) throws NotFoundServiceEx { @Override public GFUser get(String name) { - Search search = new Search(GFUser.class); + Search search = gfUserDAO.createSearch(); search.addFilterEqual("name", name); List users = gfUserDAO.search(search); @@ -86,7 +86,7 @@ public List getFullList(String nameLike, Integer page, Integer entries) throw new BadRequestServiceEx("Page and entries params should be declared together."); } - Search searchCriteria = new Search(GFUser.class); + Search searchCriteria = gfUserDAO.createSearch(); if(page != null) { searchCriteria.setMaxResults(entries); @@ -110,7 +110,7 @@ public List getList(String nameLike, Integer page, Integer entries) { @Override public long getCount(String nameLike) { - Search searchCriteria = new Search(GFUser.class); + Search searchCriteria = gfUserDAO.createCountSearch(); if (nameLike != null) { searchCriteria.addFilterILike("name", nameLike); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java index 0f04a9c3..805ad906 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/InstanceAdminServiceImpl.java @@ -60,7 +60,7 @@ public GSInstance get(long id) throws NotFoundServiceEx { @Override public GSInstance get(String name) { - Search search = new Search(GSInstance.class); + Search search = instanceDAO.createSearch(); search.addFilterEqual("name", name); List groups = instanceDAO.search(search); @@ -97,7 +97,7 @@ public List getFullList(String nameLike, Integer page, Integer entri throw new BadRequestServiceEx("Page and entries params should be declared together."); } - Search searchCriteria = new Search(GSInstance.class); + Search searchCriteria = instanceDAO.createSearch(); if(page != null) { searchCriteria.setMaxResults(entries); @@ -128,7 +128,7 @@ private List convertToShortList(List list) { @Override public long getCount(String nameLike) { - Search searchCriteria = new Search(GSInstance.class); + Search searchCriteria = instanceDAO.createCountSearch(); if (nameLike != null) { searchCriteria.addFilterILike("name", nameLike); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java index 4b5f2e60..7df23039 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleAdminServiceImpl.java @@ -144,8 +144,8 @@ public boolean delete(long id) throws NotFoundServiceEx { @Override public void deleteRulesByUser(String username) throws NotFoundServiceEx { - Search searchCriteria = new Search(Rule.class); - searchCriteria.addFilter(Filter.equal("username", username)); + Search searchCriteria = ruleDAO.createSearch(); + searchCriteria.addFilterEqual("username", username); List list = ruleDAO.search(searchCriteria); if(LOGGER.isInfoEnabled()) @@ -159,8 +159,8 @@ public void deleteRulesByUser(String username) throws NotFoundServiceEx { @Override public void deleteRulesByRole(String rolename) throws NotFoundServiceEx { - Search searchCriteria = new Search(Rule.class); - searchCriteria.addFilter(Filter.equal("rolename", rolename)); + Search searchCriteria = ruleDAO.createSearch(); + searchCriteria.addFilterEqual("rolename", rolename); List list = ruleDAO.search(searchCriteria); for (Rule rule : list) { @@ -172,8 +172,8 @@ public void deleteRulesByRole(String rolename) throws NotFoundServiceEx { @Override public void deleteRulesByInstance(long instanceId) throws NotFoundServiceEx { - Search searchCriteria = new Search(Rule.class); - searchCriteria.addFilter(Filter.equal("instance.id", instanceId)); + Search searchCriteria = ruleDAO.createSearch(); + searchCriteria.addFilterEqual("instance.id", instanceId); List list = ruleDAO.search(searchCriteria); for (Rule rule : list) { @@ -256,8 +256,8 @@ public ShortRule getRule(RuleFilter filter) throws BadRequestServiceEx { @Override public List getRulesByPriority(long priority, Integer page, Integer entries) { - Search searchCriteria = new Search(Rule.class); - searchCriteria.addFilter(Filter.greaterOrEqual("priority", priority)); + Search searchCriteria = ruleDAO.createSearch(); + searchCriteria.addFilterGreaterOrEqual("priority", priority); searchCriteria.addSortAsc("priority"); addPagingConstraints(searchCriteria, page, entries); List found = ruleDAO.search(searchCriteria); @@ -266,8 +266,8 @@ public List getRulesByPriority(long priority, Integer page, Integer e @Override public ShortRule getRuleByPriority(long priority) throws BadRequestServiceEx { - Search searchCriteria = new Search(Rule.class); - searchCriteria.addFilter(Filter.equal("priority", priority)); + Search searchCriteria = ruleDAO.createSearch(); + searchCriteria.addFilterEqual("priority", priority); List found = ruleDAO.search(searchCriteria); if(found.isEmpty()) return null; @@ -314,7 +314,7 @@ public long count(RuleFilter filter) { // Search stuff private Search buildRuleSearch(RuleFilter filter) { - Search searchCriteria = new Search(Rule.class); + Search searchCriteria = ruleDAO.createSearch(); if(filter != null) { addStringCriteria(searchCriteria, "username", filter.getUser()); @@ -333,7 +333,7 @@ private Search buildRuleSearch(RuleFilter filter) { //========================================================================= private Search buildFixedRuleSearch(RuleFilter filter) { - Search searchCriteria = new Search(Rule.class); + Search searchCriteria = ruleDAO.createSearch(); if(filter != null) { addFixedStringCriteria(searchCriteria, "username", filter.getUser()); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java index 52b84bb2..4580b1a0 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/RuleReaderServiceImpl.java @@ -599,7 +599,7 @@ protected Set validateUserRoles(RuleFilter filter) throws BadRequestServ } protected List getRuleAux(RuleFilter filter, TextFilter roleFilter) { - Search searchCriteria = new Search(Rule.class); + Search searchCriteria = ruleDAO.createSearch(); searchCriteria.addSortAsc("priority"); addStringCriteria(searchCriteria, "username", filter.getUser()); addStringCriteria(searchCriteria, "rolename", roleFilter); @@ -626,14 +626,14 @@ private void addCriteria(Search searchCriteria, String fieldName, IdNameFilter f case IDVALUE: searchCriteria.addFilterOr( - Filter.isNull(fieldName), - Filter.equal(fieldName + ".id", filter.getId())); + searchCriteria.isNull(fieldName), + searchCriteria.isEqual(fieldName + ".id", filter.getId())); break; case NAMEVALUE: searchCriteria.addFilterOr( - Filter.isNull(fieldName), - Filter.equal(fieldName + ".name", filter.getName())); + searchCriteria.isNull(fieldName), + searchCriteria.isEqual(fieldName + ".name", filter.getName())); break; default: @@ -652,8 +652,8 @@ private void addStringCriteria(Search searchCriteria, String fieldName, TextFilt case NAMEVALUE: searchCriteria.addFilterOr( - Filter.isNull(fieldName), - Filter.equal(fieldName, filter.getText())); + searchCriteria.isNull(fieldName), + searchCriteria.isEqual(fieldName, filter.getText())); break; case IDVALUE: @@ -737,7 +737,7 @@ private boolean getAdminAuth(RuleFilter filter) { } protected AdminRule getAdminAuthAux(RuleFilter filter, TextFilter roleFilter) { - Search searchCriteria = new Search(AdminRule.class); + Search searchCriteria = adminRuleDAO.createSearch(); searchCriteria.addSortAsc("priority"); addStringCriteria(searchCriteria, "username", filter.getUser()); addStringCriteria(searchCriteria, "rolename", roleFilter); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java index 6bde7a4b..44e8032e 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserAdminServiceImpl.java @@ -62,7 +62,7 @@ public GSUser get(long id) throws NotFoundServiceEx { @Override public GSUser get(String name) { - Search search = new Search(GSUser.class); + Search search = userDAO.createSearch(); search.addFilterEqual("name", name); List users = userDAO.search(search); @@ -102,7 +102,7 @@ public List getFullList(String nameLike, Integer page, Integer entries, throw new BadRequestServiceEx("Page and entries params should be declared together."); } - Search searchCriteria = new Search(GSUser.class); + Search searchCriteria = userDAO.createSearch(); if(page != null) { searchCriteria.setMaxResults(entries); @@ -130,7 +130,7 @@ public List getList(String nameLike, Integer page, Integer entries) { @Override public long getCount(String nameLike) { - Search searchCriteria = new Search(GSUser.class); + Search searchCriteria = userDAO.createCountSearch(); if (nameLike != null) { searchCriteria.addFilterILike("name", nameLike); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java index 74eb0a16..5468e8d7 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/UserGroupAdminServiceImpl.java @@ -75,7 +75,7 @@ public UserGroup get(long id) throws NotFoundServiceEx { @Override public UserGroup get(String name) { - Search search = new Search(UserGroup.class); + Search search = userGroupDAO.createSearch(); search.addFilterEqual("name", name); List groups = userGroupDAO.search(search); @@ -117,7 +117,7 @@ protected Search buildCriteria(Integer page, Integer entries, String nameLike) t if ( (page != null && entries == null) || (page == null && entries != null) ) { throw new BadRequestServiceEx("Page and entries params should be declared together."); } - Search searchCriteria = new Search(UserGroup.class); + Search searchCriteria = userGroupDAO.createSearch(); if ( page != null ) { searchCriteria.setMaxResults(entries); searchCriteria.setPage(page); diff --git a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java index 837b04dd..0bde34e4 100644 --- a/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java +++ b/src/services/core/services-impl/src/main/java/org/geoserver/geofence/services/util/FilterUtils.java @@ -10,7 +10,7 @@ import java.util.List; import org.apache.log4j.LogManager; import org.apache.log4j.Logger; -import org.geoserver.geofence.core.dao.search.Filter; +//import org.geoserver.geofence.core.dao.search.Filter; import org.geoserver.geofence.core.dao.search.Search; import org.geoserver.geofence.core.model.IPRangeProvider; import org.geoserver.geofence.services.dto.RuleFilter; @@ -109,22 +109,20 @@ public static void addCriteria(Search searchCriteria, String fieldName, RuleFilt case IDVALUE: if(filter.isIncludeDefault()) { searchCriteria.addFilterOr( - Filter.isNull(fieldName), - Filter.equal(fieldName + ".id", filter.getId())); + searchCriteria.isNull(fieldName), + searchCriteria.isEqual(fieldName + ".id", filter.getId())); } else { - searchCriteria.addFilter( - Filter.equal(fieldName + ".id", filter.getId())); + searchCriteria.addFilterEqual(fieldName + ".id", filter.getId()); } break; case NAMEVALUE: if(filter.isIncludeDefault()) { searchCriteria.addFilterOr( - Filter.isNull(fieldName), - Filter.equal(fieldName + ".name", filter.getName())); + searchCriteria.isNull(fieldName), + searchCriteria.isEqual(fieldName + ".name", filter.getName())); } else { - searchCriteria.addFilter( - Filter.equal(fieldName + ".name", filter.getName())); + searchCriteria.addFilterEqual(fieldName + ".name", filter.getName()); } break; @@ -133,7 +131,7 @@ public static void addCriteria(Search searchCriteria, String fieldName, RuleFilt } } - public static void addPagingConstraints(Search searchCriteria, Integer page, Integer entries) { + public static void addPagingConstraints(Search search, Integer page, Integer entries) { if( (page != null && entries == null) || (page ==null && entries != null)) { throw new BadRequestServiceEx("Page and entries params should be declared together."); } @@ -143,28 +141,27 @@ public static void addPagingConstraints(Search searchCriteria, Integer page, Int } if(entries != null) { - searchCriteria.setMaxResults(entries); - searchCriteria.setPage(page); + search.setMaxResults(entries); + search.setPage(page); } } - public static void addStringCriteria(Search searchCriteria, String fieldName, RuleFilter.TextFilter filter) { + public static void addStringCriteria(Search search, String fieldName, RuleFilter.TextFilter filter) { switch (filter.getType()) { case ANY: break; // no filtering case DEFAULT: - searchCriteria.addFilterNull(fieldName); + search.addFilterNull(fieldName); break; case NAMEVALUE: if(filter.isIncludeDefault()) { - searchCriteria.addFilterOr( - Filter.isNull(fieldName), - Filter.equal(fieldName, filter.getText())); + search.addFilterOr( + search.isNull(fieldName), + search.isEqual(fieldName, filter.getText())); } else { - searchCriteria.addFilter( - Filter.equal(fieldName, filter.getText())); + search.addFilterEqual(fieldName, filter.getText()); } break; @@ -183,21 +180,20 @@ public static void addStringCriteria(Search searchCriteria, String fieldName, Ru * * We're dealing with IDs here, so we'll suppose that the related object id field is called "id". */ - public static void addFixedCriteria(Search searchCriteria, String fieldName, RuleFilter.IdNameFilter filter) { + public static void addFixedCriteria(Search search, String fieldName, RuleFilter.IdNameFilter filter) { switch (filter.getType()) { case ANY: throw new BadRequestServiceEx(fieldName + " should be a fixed search and can't be ANY"); case DEFAULT: - searchCriteria.addFilterNull(fieldName); + search.addFilterNull(fieldName); break; case IDVALUE: if(filter.isIncludeDefault()) { throw new BadRequestServiceEx(fieldName + " should be a fixed search"); } else { - searchCriteria.addFilter( - Filter.equal(fieldName + ".id", filter.getId())); + search.addFilterEqual(fieldName + ".id", filter.getId()); } break; @@ -206,8 +202,7 @@ public static void addFixedCriteria(Search searchCriteria, String fieldName, Rul throw new BadRequestServiceEx(fieldName + " should be a fixed search"); } else { - searchCriteria.addFilter( - Filter.equal(fieldName + ".name", filter.getName())); + search.addFilterEqual(fieldName + ".name", filter.getName()); } break; @@ -219,21 +214,20 @@ public static void addFixedCriteria(Search searchCriteria, String fieldName, Rul - public static void addFixedStringCriteria(Search searchCriteria, String fieldName, RuleFilter.TextFilter filter) { + public static void addFixedStringCriteria(Search search, String fieldName, RuleFilter.TextFilter filter) { switch (filter.getType()) { case ANY: throw new BadRequestServiceEx(fieldName + " should be a fixed search and can't be ANY"); case DEFAULT: - searchCriteria.addFilterNull(fieldName); + search.addFilterNull(fieldName); break; case NAMEVALUE: if(filter.isIncludeDefault()) { throw new BadRequestServiceEx(fieldName + " should be a fixed search"); } else { - searchCriteria.addFilter( - Filter.equal(fieldName, filter.getText())); + search.addFilterEqual(fieldName, filter.getText()); } break;