From 66714eedca068fe6453c97319c6b27e89f5c4ca1 Mon Sep 17 00:00:00 2001 From: Ariel Backenroth Date: Fri, 6 Oct 2006 07:49:20 +0000 Subject: [PATCH] fix a bug where getTempalteType was screwing up and throwin NullPointerExceptions when recieving multiple results for a search query it was expeting only one result from (didn't realize it was tokenizing queries - thought it would be the exact match thing...) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/WCM-DEV2/root@4047 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../web/templating/TemplatingService.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/source/java/org/alfresco/web/templating/TemplatingService.java b/source/java/org/alfresco/web/templating/TemplatingService.java index a68fc0e4c2..1812a96de4 100644 --- a/source/java/org/alfresco/web/templating/TemplatingService.java +++ b/source/java/org/alfresco/web/templating/TemplatingService.java @@ -141,9 +141,8 @@ public final class TemplatingService implements Serializable final SearchParameters sp = new SearchParameters(); sp.addStore(Repository.getStoreRef()); sp.setLanguage(SearchService.LANGUAGE_LUCENE); - final String q = "ASPECT:\"" + WCMModel.ASPECT_TEMPLATE + "\""; - sp.setQuery(q); - LOGGER.debug("running query [" + q + "]"); + sp.setQuery("ASPECT:\"" + WCMModel.ASPECT_TEMPLATE + "\""); + LOGGER.debug("running query [" + sp.getQuery() + "]"); final ResultSet rs = this.searchService.query(sp); LOGGER.debug("received " + rs.length() + " results"); final Collection result = new LinkedList(); @@ -172,8 +171,21 @@ public final class TemplatingService implements Serializable sp.setQuery("ASPECT:\"" + WCMModel.ASPECT_TEMPLATE + "\" AND @" + Repository.escapeQName(ContentModel.PROP_TITLE) + ":\"" + name + "\""); + LOGGER.debug("running query [" + sp.getQuery() + "]"); final ResultSet rs = this.searchService.query(sp); - return (rs.length() == 1 ? this.newTemplateType(rs.getNodeRef(0)) : null); + NodeRef result = null; + for (ResultSetRow row : rs) + { + final NodeRef nr = row.getNodeRef(); + if (this.nodeService.getProperty(nr, ContentModel.PROP_TITLE).equals(name)) + { + result = nr; + break; + } + } + if (result == null && LOGGER.isDebugEnabled()) + LOGGER.debug("unable to find tempalte type " + name); + return result != null ? this.newTemplateType(result) : null; } catch (RuntimeException re) {