From 0cdf8e216f9f47cb05f569f596299a662c6b1b30 Mon Sep 17 00:00:00 2001 From: Kevin Roast Date: Fri, 12 May 2006 16:06:00 +0000 Subject: [PATCH] . Added support for folder-type restrictions in Advanced Search config - Added forums folder type to list by default - Added folder-type drop-down to Advanced Search UI git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2878 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/messages/webclient.properties | 1 + config/alfresco/web-client-config.xml | 7 +- .../alfresco/web/bean/AdvancedSearchBean.java | 98 +++++++++++++++++-- .../org/alfresco/web/bean/SearchContext.java | 42 +++++++- .../config/AdvancedSearchConfigElement.java | 40 ++++++++ .../config/AdvancedSearchElementReader.java | 19 ++++ source/web/jsp/dialog/advanced-search.jsp | 8 ++ source/web/jsp/trashcan/item-details.jsp | 2 +- source/web/jsp/trashcan/trash-list.jsp | 2 +- 9 files changed, 206 insertions(+), 13 deletions(-) diff --git a/config/alfresco/messages/webclient.properties b/config/alfresco/messages/webclient.properties index 2e2b6b2027..d4eb7c802f 100644 --- a/config/alfresco/messages/webclient.properties +++ b/config/alfresco/messages/webclient.properties @@ -300,6 +300,7 @@ saved_search_warning=This operation will attempt to overwrite the existing saved user_searches=Your Searches global_searches=Public Searches save_search_global=Save as a public search available to all users. +folder_type=Folder Type # Forum messages forums=Forum Space diff --git a/config/alfresco/web-client-config.xml b/config/alfresco/web-client-config.xml index c1ca929b30..37945d35a2 100644 --- a/config/alfresco/web-client-config.xml +++ b/config/alfresco/web-client-config.xml @@ -151,9 +151,14 @@ - + + + + + + diff --git a/source/java/org/alfresco/web/bean/AdvancedSearchBean.java b/source/java/org/alfresco/web/bean/AdvancedSearchBean.java index 106b9a7b20..44047c6587 100644 --- a/source/java/org/alfresco/web/bean/AdvancedSearchBean.java +++ b/source/java/org/alfresco/web/bean/AdvancedSearchBean.java @@ -522,6 +522,22 @@ public class AdvancedSearchBean this.contentType = contentType; } + /** + * @return Returns the folder type currenty selected + */ + public String getFolderType() + { + return this.folderType; + } + + /** + * @param folderType Sets the currently selected folder type + */ + public void setFolderType(String folderType) + { + this.folderType = folderType; + } + /** * @return Returns the contentFormat. */ @@ -571,16 +587,17 @@ public class AdvancedSearchBean { FacesContext context = FacesContext.getCurrentInstance(); + DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService(); + // add the well known cm:content object type by default this.contentTypes = new ArrayList(5); this.contentTypes.add(new SelectItem(ContentModel.TYPE_CONTENT.toString(), - Application.getMessage(context, MSG_CONTENT))); + dictionaryService.getType(ContentModel.TYPE_CONTENT).getTitle())); // add any configured content sub-types to the list List types = getSearchConfig().getContentTypes(); if (types != null) { - DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService(); for (String type : types) { QName idQName = Repository.resolveToQName(type); @@ -613,6 +630,58 @@ public class AdvancedSearchBean return this.contentTypes; } + /** + * @return Returns a list of folder object types to allow the user to select from + */ + public List getFolderTypes() + { + if (this.folderTypes == null) + { + FacesContext context = FacesContext.getCurrentInstance(); + + DictionaryService dictionaryService = Repository.getServiceRegistry(context).getDictionaryService(); + + // add the well known cm:folder object type by default + this.folderTypes = new ArrayList(5); + this.folderTypes.add(new SelectItem(ContentModel.TYPE_FOLDER.toString(), + dictionaryService.getType(ContentModel.TYPE_FOLDER).getTitle())); + + // add any configured folder sub-types to the list + List types = getSearchConfig().getFolderTypes(); + if (types != null) + { + for (String type : types) + { + QName idQName = Repository.resolveToQName(type); + if (idQName != null) + { + TypeDefinition typeDef = dictionaryService.getType(idQName); + + if (typeDef != null && dictionaryService.isSubClass(typeDef.getName(), ContentModel.TYPE_FOLDER)) + { + // try and get label from the dictionary + String label = typeDef.getTitle(); + + // else just use the localname + if (label == null) + { + label = idQName.getLocalName(); + } + + this.folderTypes.add(new SelectItem(idQName.toString(), label)); + } + } + } + + // make sure the list is sorted by the label + QuickSort sorter = new QuickSort(this.folderTypes, "label", true, IDataContainer.SORT_CASEINSENSITIVE); + sorter.sort(); + } + } + + return this.folderTypes; + } + /** * @return Returns a list of content formats to allow the user to select from */ @@ -662,6 +731,7 @@ public class AdvancedSearchBean this.lookin = LOOKIN_ALL; this.contentType = null; this.contentFormat = null; + this.folderType = null; this.location = null; this.locationChildren = true; this.categories = new ArrayList(2); @@ -822,6 +892,12 @@ public class AdvancedSearchBean search.setContentType(this.contentType); } + // folder type restriction + if (this.folderType != null) + { + search.setFolderType(this.folderType); + } + // set the Search Context onto the top-level navigator bean // this causes the browse screen to switch into search results view this.navigator.setSearchContext(search); @@ -1168,6 +1244,7 @@ public class AdvancedSearchBean this.contentType = search.getContentType(); this.contentFormat = search.getMimeType(); + this.folderType = search.getFolderType(); this.description = search.getAttributeQuery(ContentModel.PROP_DESCRIPTION); this.title = search.getAttributeQuery(ContentModel.PROP_TITLE); @@ -1476,7 +1553,6 @@ public class AdvancedSearchBean // ------------------------------------------------------------------------------ // Private data - private static final String MSG_CONTENT = "content"; private static final String MSG_ALL_FORMATS = "all_formats"; private static final String MSG_ERROR_SAVE_SEARCH = "error_save_search"; private static final String MSG_ERROR_RESTORE_SEARCH = "error_restore_search"; @@ -1536,17 +1612,23 @@ public class AdvancedSearchBean /** lookup of custom property QName string to DataTypeDefinition for the property */ private Map customPropertyLookup = null; - /** content types to for restricting searches */ - private List contentTypes; - /** content format list restricting searches */ private List contentFormats; + /** content format selection */ + private String contentFormat; + /** content type selection */ private String contentType; - /** content format selection */ - private String contentFormat; + /** content types for restricting searches */ + private List contentTypes; + + /** folder type selection */ + private String folderType; + + /** folder types for restricting searches */ + private List folderTypes; /** the text to search for */ private String text = ""; diff --git a/source/java/org/alfresco/web/bean/SearchContext.java b/source/java/org/alfresco/web/bean/SearchContext.java index 5aea16661e..f100d0d4d8 100644 --- a/source/java/org/alfresco/web/bean/SearchContext.java +++ b/source/java/org/alfresco/web/bean/SearchContext.java @@ -73,6 +73,7 @@ public final class SearchContext implements Serializable private static final String ELEMENT_ATTRIBUTES = "attributes"; private static final String ELEMENT_MIMETYPE = "mimetype"; private static final String ELEMENT_CONTENT_TYPE = "content-type"; + private static final String ELEMENT_FOLDER_TYPE = "folder-type"; private static final String ELEMENT_CATEGORY = "category"; private static final String ELEMENT_CATEGORIES = "categories"; private static final String ELEMENT_LOCATION = "location"; @@ -104,6 +105,9 @@ public final class SearchContext implements Serializable /** categories to add to the search */ private String[] categories = new String[0]; + /** folder type to restrict search against */ + private String folderType = null; + /** content type to restrict search against */ private String contentType = null; @@ -384,8 +388,16 @@ public final class SearchContext implements Serializable fileTypeQuery = " TYPE:\"{" + NamespaceService.CONTENT_MODEL_1_0_URI + "}content\" "; } - // match against FOLDER type - String folderTypeQuery = " TYPE:\"{" + NamespaceService.CONTENT_MODEL_1_0_URI + "}folder\" "; + // match against appropriate folder type + String folderTypeQuery; + if (folderType != null) + { + folderTypeQuery = " TYPE:\"" + folderType + "\" "; + } + else + { + folderTypeQuery = " TYPE:\"{" + NamespaceService.CONTENT_MODEL_1_0_URI + "}folder\" "; + } String fullTextQuery = fullTextBuf.toString(); String nameAttrQuery = nameAttrBuf.toString(); @@ -595,6 +607,22 @@ public final class SearchContext implements Serializable this.contentType = contentType; } + /** + * @return Returns the folderType. + */ + public String getFolderType() + { + return this.folderType; + } + + /** + * @param folderType The folder type to restrict attribute search against. + */ + public void setFolderType(String folderType) + { + this.folderType = folderType; + } + /** * @return Returns the mimeType. */ @@ -690,6 +718,7 @@ public final class SearchContext implements Serializable * XPath * * String + * String * String * * String @@ -735,6 +764,10 @@ public final class SearchContext implements Serializable { root.addElement(ELEMENT_CONTENT_TYPE).addText(this.contentType); } + if (this.folderType != null) + { + root.addElement(ELEMENT_FOLDER_TYPE).addText(this.folderType); + } if (this.mimeType != null && this.mimeType.length() != 0) { root.addElement(ELEMENT_MIMETYPE).addText(this.mimeType); @@ -834,6 +867,11 @@ public final class SearchContext implements Serializable { this.contentType = contentTypeElement.getText(); } + Element folderTypeElement = rootElement.element(ELEMENT_FOLDER_TYPE); + if (folderTypeElement != null) + { + this.folderType = folderTypeElement.getText(); + } Element mimetypeElement = rootElement.element(ELEMENT_MIMETYPE); if (mimetypeElement != null) { diff --git a/source/java/org/alfresco/web/config/AdvancedSearchConfigElement.java b/source/java/org/alfresco/web/config/AdvancedSearchConfigElement.java index c7095fd592..7f32a07573 100644 --- a/source/java/org/alfresco/web/config/AdvancedSearchConfigElement.java +++ b/source/java/org/alfresco/web/config/AdvancedSearchConfigElement.java @@ -33,6 +33,7 @@ public class AdvancedSearchConfigElement extends ConfigElementAdapter public static final String CONFIG_ELEMENT_ID = "advanced-search"; private List contentTypes = null; + private List folderTypes = null; private List customProps = null; /** @@ -78,6 +79,13 @@ public class AdvancedSearchConfigElement extends ConfigElementAdapter combinedElement.addContentType(type); } } + if (this.folderTypes != null) + { + for (String type : this.folderTypes) + { + combinedElement.addFolderType(type); + } + } if (this.customProps != null) { @@ -139,6 +147,38 @@ public class AdvancedSearchConfigElement extends ConfigElementAdapter } } + /** + * @return Returns the folderTypes. + */ + public List getFolderTypes() + { + return this.folderTypes; + } + + /** + * @param folderTypes The folderTypes to set. + */ + /*package*/ void setFolderTypes(List folderTypes) + { + this.folderTypes = folderTypes; + } + + /** + * @param folderType Adds the given folder type to the list + */ + /*package*/ void addFolderType(String folderType) + { + if (this.folderTypes == null) + { + this.folderTypes = new ArrayList(3); + } + + if (this.folderTypes.contains(folderType) == false) + { + this.folderTypes.add(folderType); + } + } + /** * @return Returns the customProps. */ diff --git a/source/java/org/alfresco/web/config/AdvancedSearchElementReader.java b/source/java/org/alfresco/web/config/AdvancedSearchElementReader.java index 62d9e05ae6..8ee3299349 100644 --- a/source/java/org/alfresco/web/config/AdvancedSearchElementReader.java +++ b/source/java/org/alfresco/web/config/AdvancedSearchElementReader.java @@ -34,6 +34,7 @@ import org.dom4j.Element; public class AdvancedSearchElementReader implements ConfigElementReader { public static final String ELEMENT_CONTENTTYPES = "content-types"; + public static final String ELEMENT_FOLDERTYPES = "folder-types"; public static final String ELEMENT_TYPE = "type"; public static final String ELEMENT_CUSTOMPROPS = "custom-properties"; public static final String ELEMENT_METADATA = "meta-data"; @@ -81,6 +82,24 @@ public class AdvancedSearchElementReader implements ConfigElementReader configElement.setContentTypes(types); } + // get the list of folder types + Element folderTypes = element.element(ELEMENT_FOLDERTYPES); + if (folderTypes != null) + { + Iterator typesItr = folderTypes.elementIterator(ELEMENT_TYPE); + List types = new ArrayList(5); + while (typesItr.hasNext()) + { + Element folderType = typesItr.next(); + String type = folderType.attributeValue(ATTRIBUTE_NAME); + if (type != null) + { + types.add(type); + } + } + configElement.setFolderTypes(types); + } + // get the list of custom properties to display Element customProps = element.element(ELEMENT_CUSTOMPROPS); if (customProps != null) diff --git a/source/web/jsp/dialog/advanced-search.jsp b/source/web/jsp/dialog/advanced-search.jsp index ad7b91e617..0e45054bbb 100644 --- a/source/web/jsp/dialog/advanced-search.jsp +++ b/source/web/jsp/dialog/advanced-search.jsp @@ -261,6 +261,14 @@ + + + +
: + + + +
: diff --git a/source/web/jsp/trashcan/item-details.jsp b/source/web/jsp/trashcan/item-details.jsp index 76f329a9e5..4ac3d3140d 100644 --- a/source/web/jsp/trashcan/item-details.jsp +++ b/source/web/jsp/trashcan/item-details.jsp @@ -158,7 +158,7 @@
- +
diff --git a/source/web/jsp/trashcan/trash-list.jsp b/source/web/jsp/trashcan/trash-list.jsp index 9812c118ff..28bc203b61 100644 --- a/source/web/jsp/trashcan/trash-list.jsp +++ b/source/web/jsp/trashcan/trash-list.jsp @@ -286,7 +286,7 @@
- +