mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Made the system users page use a search instead of showing all users
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2183 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -564,6 +564,7 @@ http_request_headers=HTTP Request Headers
|
||||
system_props=System Properties
|
||||
hide_details=Hide Details
|
||||
show_details=Show Details
|
||||
user_search_info=To find a user search for them using their first name, last name and/or user name. Alternatively to see all users click 'Show All', however, this may take some time if there are a lot of users in the system.
|
||||
|
||||
# Content Wizard messages
|
||||
add_content_title=Add Content Wizard
|
||||
|
@@ -17,6 +17,8 @@
|
||||
package org.alfresco.web.bean.users;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -28,12 +30,14 @@ import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.search.SearchParameters;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.web.app.Application;
|
||||
import org.alfresco.web.app.context.IContextListener;
|
||||
import org.alfresco.web.app.context.UIContextService;
|
||||
import org.alfresco.web.bean.LoginBean;
|
||||
import org.alfresco.web.bean.repository.MapNode;
|
||||
import org.alfresco.web.bean.repository.Node;
|
||||
import org.alfresco.web.bean.repository.Repository;
|
||||
import org.alfresco.web.ui.common.Utils;
|
||||
@@ -58,7 +62,7 @@ public class UsersBean implements IContextListener
|
||||
|
||||
/** SearchService bean reference */
|
||||
private SearchService searchService;
|
||||
|
||||
|
||||
/** AuthenticationService bean reference */
|
||||
private AuthenticationService authenticationService;
|
||||
|
||||
@@ -68,9 +72,11 @@ public class UsersBean implements IContextListener
|
||||
/** action context */
|
||||
private Node person = null;
|
||||
|
||||
private List<Node> users = Collections.<Node>emptyList();
|
||||
|
||||
private String password = null;
|
||||
private String confirm = null;
|
||||
|
||||
private String searchCriteria = null;
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// Construction
|
||||
@@ -132,10 +138,25 @@ public class UsersBean implements IContextListener
|
||||
*/
|
||||
public List<Node> getUsers()
|
||||
{
|
||||
return Repository.getUsers(FacesContext.getCurrentInstance(), this.nodeService,
|
||||
this.searchService);
|
||||
return this.users;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the search criteria
|
||||
*/
|
||||
public String getSearchCriteria()
|
||||
{
|
||||
return searchCriteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param searchCriteria The search criteria to select
|
||||
*/
|
||||
public void setSearchCriteria(String searchCriteria)
|
||||
{
|
||||
this.searchCriteria = searchCriteria;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns the confirm password.
|
||||
*/
|
||||
@@ -294,6 +315,103 @@ public class UsersBean implements IContextListener
|
||||
return outcome;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler called when the user wishes to search for a user
|
||||
*
|
||||
* @param event The event
|
||||
*/
|
||||
public void search(ActionEvent event)
|
||||
{
|
||||
this.usersRichList.setValue(null);
|
||||
|
||||
if (this.searchCriteria == null || this.searchCriteria.length() == 0)
|
||||
{
|
||||
this.users = Collections.<Node>emptyList();
|
||||
}
|
||||
else
|
||||
{
|
||||
FacesContext context = FacesContext.getCurrentInstance();
|
||||
UserTransaction tx = null;
|
||||
|
||||
try
|
||||
{
|
||||
tx = Repository.getUserTransaction(context, true);
|
||||
tx.begin();
|
||||
|
||||
// define the query to find people by their first or last name
|
||||
String query = "( TYPE:\"{http://www.alfresco.org/model/content/1.0}person\") AND " +
|
||||
"((@\\{http\\://www.alfresco.org/model/content/1.0\\}firstName:" + this.searchCriteria +
|
||||
"*) OR (@\\{http\\://www.alfresco.org/model/content/1.0\\}lastName:" + this.searchCriteria +
|
||||
"*) OR (@\\{http\\://www.alfresco.org/model/content/1.0\\}userName:" + this.searchCriteria +
|
||||
"*)))";
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Query: " + query);
|
||||
|
||||
// define the search parameters
|
||||
SearchParameters params = new SearchParameters();
|
||||
params.setLanguage(SearchService.LANGUAGE_LUCENE);
|
||||
params.addStore(Repository.getStoreRef());
|
||||
params.setQuery(query);
|
||||
|
||||
List<NodeRef> people = this.searchService.query(params).getNodeRefs();
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Found " + people.size() + " users");
|
||||
|
||||
this.users = new ArrayList<Node>(people.size());
|
||||
|
||||
for (NodeRef nodeRef : people)
|
||||
{
|
||||
// create our Node representation
|
||||
MapNode node = new MapNode(nodeRef);
|
||||
|
||||
// set data binding properties
|
||||
// this will also force initialisation of the props now during the UserTransaction
|
||||
// it is much better for performance to do this now rather than during page bind
|
||||
Map<String, Object> props = node.getProperties();
|
||||
props.put("fullName", ((String)props.get("firstName")) + ' ' + ((String)props.get("lastName")));
|
||||
NodeRef homeFolderNodeRef = (NodeRef)props.get("homeFolder");
|
||||
if (homeFolderNodeRef != null)
|
||||
{
|
||||
props.put("homeSpace", homeFolderNodeRef);
|
||||
}
|
||||
|
||||
this.users.add(node);
|
||||
}
|
||||
|
||||
// commit the transaction
|
||||
tx.commit();
|
||||
}
|
||||
catch (InvalidNodeRefException refErr)
|
||||
{
|
||||
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
|
||||
context, Repository.ERROR_NODEREF), new Object[] {"root"}) );
|
||||
this.users = Collections.<Node>emptyList();
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
catch (Exception err)
|
||||
{
|
||||
Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
|
||||
context, Repository.ERROR_GENERIC), err.getMessage()), err );
|
||||
this.users = Collections.<Node>emptyList();
|
||||
try { if (tx != null) {tx.rollback();} } catch (Exception tex) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Action handler to show all the users currently in the system
|
||||
*
|
||||
* @param event The event
|
||||
*/
|
||||
public void showAll(ActionEvent event)
|
||||
{
|
||||
this.usersRichList.setValue(null);
|
||||
|
||||
this.users = Repository.getUsers(FacesContext.getCurrentInstance(),
|
||||
this.nodeService, this.searchService);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
// IContextListener implementation
|
||||
|
@@ -111,6 +111,23 @@
|
||||
<%-- Users List --%>
|
||||
<a:panel id="users-panel" border="white" bgcolor="white" titleBorder="blue" titleBgcolor="#D3E6FE" styleClass="mainSubTitle" label="#{msg.users}">
|
||||
|
||||
<% PanelGenerator.generatePanelStart(out, request.getContextPath(), "yellowInner", "#ffffcc"); %>
|
||||
<table cellpadding="0" cellspacing="0" border="0" width="100%">
|
||||
<tr>
|
||||
<td valign=top style="padding-top:2px" width=20><h:graphicImage url="/images/icons/info_icon.gif" width="16" height="16"/></td>
|
||||
<td class="mainSubText">
|
||||
<h:outputText value="#{msg.user_search_info}" />
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<% PanelGenerator.generatePanelEnd(out, request.getContextPath(), "yellowInner"); %>
|
||||
|
||||
<div style="padding: 6px;" />
|
||||
<h:inputText value="#{UsersBean.searchCriteria}" size="35" maxlength="1024" />
|
||||
<h:commandButton value="Search" actionListener="#{UsersBean.search}" />
|
||||
<h:commandButton value="Show All" actionListener="#{UsersBean.showAll}" />
|
||||
<div style="padding: 6px;" />
|
||||
|
||||
<a:richList id="users-list" binding="#{UsersBean.usersRichList}" viewMode="details" pageSize="10"
|
||||
styleClass="recordSet" headerStyleClass="recordSetHeader" rowStyleClass="recordSetRow" altRowStyleClass="recordSetRowAlt" width="100%"
|
||||
value="#{UsersBean.users}" var="r" initialSortColumn="userName" initialSortDescending="true">
|
||||
|
Reference in New Issue
Block a user