This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository coselmar. See http://git.codelutin.com/coselmar.git commit 34460c6a07609162fac117d0e01c29bfba263f2f Author: Yannick Martel <martel@©odelutin.com> Date: Fri Jan 2 17:00:07 2015 +0100 review DocumentTopiaDAO to search with keywords also on title, summary and authors --- .../fr/ifremer/coselmar/persistence/DaoUtils.java | 5 +++ .../persistence/entity/DocumentTopiaDao.java | 37 ++++++++++++++++++---- .../coselmar/services/v1/DocumentsWebService.java | 1 - 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java index e604803..2435ab7 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/DaoUtils.java @@ -133,4 +133,9 @@ public class DaoUtils { return result; } + public static String orAttributeContains(String entityAlias, String entityAttributeName, Map<String, Object> args, Object value) { + String result = getQueryForAttributeContains(entityAlias, entityAttributeName, args, value, "OR"); + return result; + } + } diff --git a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java index ef773ee..7bd5fc8 100644 --- a/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java +++ b/coselmar-persistence/src/main/java/fr/ifremer/coselmar/persistence/entity/DocumentTopiaDao.java @@ -34,12 +34,26 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { public List<Document> findAllContainingAllKeywords(List<String> keywords) { - InnerTopiaQueryBuilderAddCriteriaOrRunQueryStep<Document> queryBuilder = newQueryBuilder(); - for (String keyword : keywords) { - queryBuilder.addContains(Document.PROPERTY_KEYWORDS, keyword); + StringBuilder hqlBuilder = new StringBuilder("FROM " + Document.class.getName() + " D"); + Map<String, Object> args = new HashMap<>(); + + if (keywords != null) { + hqlBuilder.append(" WHERE ( 1 = 0 "); + for (String keyword : keywords) { + String nameClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_NAME, args, keyword); + String summaryClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_SUMMARY, args, keyword); + String authorsClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_AUTHORS, args, keyword); + String containsKeyword = DaoUtils.orAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); + + hqlBuilder.append(nameClause); + hqlBuilder.append(summaryClause); + hqlBuilder.append(authorsClause); + hqlBuilder.append(containsKeyword); + } + hqlBuilder.append(" )"); } - List<Document> documents = queryBuilder.findAll(); + List<Document> documents = forHql(hqlBuilder.toString(), args).findAll(); return documents; } @@ -59,14 +73,25 @@ public class DocumentTopiaDao extends AbstractDocumentTopiaDao<Document> { hqlBuilder.append(" OR ( " + privacyPrivateCondition + " " + ownerCondition + " ) )"); - // Manage keywords + // Manage keywords search in : title, summary, authors and keywords + if (keywords != null) { + hqlBuilder.append(" AND ( 1 = 0 "); for (String keyword : keywords) { - String containsKeyword = DaoUtils.andAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); + String nameClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_NAME, args, keyword); + String summaryClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_SUMMARY, args, keyword); + String authorsClause = DaoUtils.orAttributeLike("D", Document.PROPERTY_AUTHORS, args, keyword); + String containsKeyword = DaoUtils.orAttributeContains("D", Document.PROPERTY_KEYWORDS, args, keyword); + + hqlBuilder.append(nameClause); + hqlBuilder.append(summaryClause); + hqlBuilder.append(authorsClause); hqlBuilder.append(containsKeyword); } + hqlBuilder.append(" )"); } + List<Document> documents = forHql(hqlBuilder.toString(), args).findAll(); return documents; diff --git a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java index e16667e..c8f62ac 100644 --- a/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java +++ b/coselmar-rest/src/main/java/fr/ifremer/coselmar/services/v1/DocumentsWebService.java @@ -149,7 +149,6 @@ public class DocumentsWebService extends CoselmarWebServiceSupport { List<DocumentBean> result = new ArrayList<>(documentList.size()); for (Document document : documentList) { - //TODO ymartel 20141103 : manage file ? String lightId = getPersistenceContext().getTopiaIdFactory().getRandomPart(document.getTopiaId()); DocumentBean documentBean = BeanEntityConverter.toBean(lightId, document); result.add(documentBean); -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.