dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24880
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12243: Web api, made search for users work properly
------------------------------------------------------------
revno: 12243
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-25 16:33:15 +0200
message:
Web api, made search for users work properly
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2013-09-14 19:05:29 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java 2013-09-25 14:33:15 +0000
@@ -146,6 +146,10 @@
int getUsersByOrganisationUnitCountByName( OrganisationUnit orgUnit, String name );
List<User> getUsersByUid( List<String> uids );
+
+ User searchForUser( String query );
+
+ List<User> queryForUsers( String query );
// -------------------------------------------------------------------------
// UserCredentials
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2013-09-16 11:22:02 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2013-09-25 14:33:15 +0000
@@ -227,18 +227,18 @@
{
Set<T> uniqueObjects = new HashSet<T>();
- T object = get( clazz, query );
+ T uidObject = get( clazz, query );
- if ( object != null )
+ if ( uidObject != null )
{
- uniqueObjects.add( object );
+ uniqueObjects.add( uidObject );
}
- object = getByCode( clazz, query );
+ T codeObject = getByCode( clazz, query );
- if ( object != null )
+ if ( codeObject != null )
{
- uniqueObjects.add( object );
+ uniqueObjects.add( codeObject );
}
uniqueObjects.addAll( getLikeName( clazz, query ) );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2013-09-14 19:05:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java 2013-09-25 14:33:15 +0000
@@ -29,6 +29,7 @@
*/
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
@@ -282,6 +283,35 @@
{
return userCredentialsStore.getUsersWithoutOrganisationUnitCountByName( userName );
}
+
+ public User searchForUser( String query )
+ {
+ User user = userStore.getByUid( query );
+
+ if ( user == null )
+ {
+ UserCredentials credentials = userCredentialsStore.getUserCredentialsByUsername( query );
+ user = credentials != null ? credentials.getUser() : null;
+ }
+
+ return user;
+ }
+
+ public List<User> queryForUsers( String query )
+ {
+ List<User> users = new ArrayList<User>();
+
+ User uidUser = userStore.getByUid( query );
+
+ if ( uidUser != null )
+ {
+ users.add( uidUser );
+ }
+
+ users.addAll( userStore.getAllLikeNameOrderedName( query, 0, 1000 ) ); //TODO
+
+ return users;
+ }
// -------------------------------------------------------------------------
// UserAuthorityGroup
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2013-09-25 13:51:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2013-09-25 14:33:15 +0000
@@ -157,7 +157,7 @@
Model model, HttpServletRequest request, HttpServletResponse response ) throws Exception
{
WebOptions options = new WebOptions( parameters );
- T entity = manager.search( getEntityClass(), query );
+ T entity = searchForEntity( getEntityClass(), query );
if ( entity == null )
{
@@ -177,7 +177,7 @@
return StringUtils.uncapitalize( getEntitySimpleName() );
}
-
+
//--------------------------------------------------------------------------
// POST
//--------------------------------------------------------------------------
@@ -266,6 +266,11 @@
// Helpers
//--------------------------------------------------------------------------
+ protected T searchForEntity( Class<T> clazz, String query )
+ {
+ return manager.search( clazz, query );
+ }
+
protected List<T> getEntityList( WebMetaData metaData, WebOptions options )
{
List<T> entityList;
@@ -295,7 +300,7 @@
protected List<T> queryForEntityList( WebMetaData metaData, WebOptions options, String query )
{
- List<T> entityList = new ArrayList<T>( manager.filter( getEntityClass(), query ) );
+ List<T> entityList = queryForList( getEntityClass(), query );
if ( options.hasPaging() )
{
@@ -307,6 +312,11 @@
return entityList;
}
+
+ protected List<T> queryForList( Class<T> clazz, String query )
+ {
+ return new ArrayList<T>( manager.filter( getEntityClass(), query ) );
+ }
protected T getEntity( String uid )
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java 2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/user/UserController.java 2013-09-25 14:33:15 +0000
@@ -110,4 +110,20 @@
{
return userService.getUser( uid );
}
+
+ //--------------------------------------------------------------------------
+ // Overrides
+ //--------------------------------------------------------------------------
+
+ @Override
+ public User searchForEntity( Class<User> clazz, String query )
+ {
+ return userService.searchForUser( query );
+ }
+
+ @Override
+ public List<User> queryForList( Class<User> clazz, String query )
+ {
+ return userService.queryForUsers( query );
+ }
}