. 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
This commit is contained in:
Kevin Roast
2006-05-12 16:06:00 +00:00
parent fbe26a49f2
commit 0cdf8e216f
9 changed files with 206 additions and 13 deletions

View File

@@ -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<SelectItem>(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<String> 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<SelectItem> 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<SelectItem>(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<String> 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<Node>(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<String, DataTypeDefinition> customPropertyLookup = null;
/** content types to for restricting searches */
private List<SelectItem> contentTypes;
/** content format list restricting searches */
private List<SelectItem> 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<SelectItem> contentTypes;
/** folder type selection */
private String folderType;
/** folder types for restricting searches */
private List<SelectItem> folderTypes;
/** the text to search for */
private String text = "";

View File

@@ -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
* <category>XPath</category>
* </categories>
* <content-type>String</content-type>
* <folder-type>String</folder-type>
* <mimetype>String</mimetype>
* <attributes>
* <attribute name="String">String</attribute>
@@ -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)
{

View File

@@ -33,6 +33,7 @@ public class AdvancedSearchConfigElement extends ConfigElementAdapter
public static final String CONFIG_ELEMENT_ID = "advanced-search";
private List<String> contentTypes = null;
private List<String> folderTypes = null;
private List<CustomProperty> 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<String> getFolderTypes()
{
return this.folderTypes;
}
/**
* @param folderTypes The folderTypes to set.
*/
/*package*/ void setFolderTypes(List<String> 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<String>(3);
}
if (this.folderTypes.contains(folderType) == false)
{
this.folderTypes.add(folderType);
}
}
/**
* @return Returns the customProps.
*/

View File

@@ -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<Element> typesItr = folderTypes.elementIterator(ELEMENT_TYPE);
List<String> types = new ArrayList<String>(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)