add roles to list users
This commit is contained in:
+10
-18
@@ -5,23 +5,6 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.api;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.commands.service.PortfolioCommandSourceWritePlatformService;
|
||||
@@ -38,6 +21,15 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Context;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Path("/users")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@@ -79,7 +71,7 @@ public class UsersApiResource {
|
||||
|
||||
this.context.authenticatedUser().validateHasReadPermission(this.resourceNameForPermissions);
|
||||
|
||||
final Collection<AppUserData> users = this.readPlatformService.retrieveAllUsers(); // this.readPlatformService.retrieveAllUsersWithRoles();
|
||||
final Collection<AppUserData> users = this.readPlatformService.retrieveAllUsers();
|
||||
|
||||
final ApiRequestJsonSerializationSettings settings = this.apiRequestParameterHelper.process(uriInfo.getQueryParameters());
|
||||
return this.toApiJsonSerializer.serialize(settings, users, this.RESPONSE_DATA_PARAMETERS);
|
||||
|
||||
Regular → Executable
+19
-2
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.organisation.office.data.OfficeData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Immutable data object for application user data.
|
||||
*/
|
||||
@@ -68,4 +68,21 @@ public class AppUserData {
|
||||
public String username() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
AppUserData that = (AppUserData) o;
|
||||
|
||||
if (id != null ? !id.equals(that.id) : that.id != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id != null ? id.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -5,10 +5,10 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.useradministration.data.AppUserData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface AppUserReadPlatformService {
|
||||
|
||||
Collection<AppUserData> retrieveAllUsers();
|
||||
@@ -18,6 +18,4 @@ public interface AppUserReadPlatformService {
|
||||
AppUserData retrieveNewUserDetails();
|
||||
|
||||
AppUserData retrieveUser(Long userId);
|
||||
|
||||
Collection<AppUserData> retrieveAllUsersWithRoles();
|
||||
}
|
||||
+16
-24
@@ -5,13 +5,6 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
|
||||
@@ -29,6 +22,12 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
@Service
|
||||
public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformService {
|
||||
|
||||
@@ -57,7 +56,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
final String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
final String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
final AppUserMapper mapper = new AppUserMapper();
|
||||
final AppUserMapper mapper = new AppUserMapper(this.roleReadPlatformService);
|
||||
final String sql = "select " + mapper.schema();
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { hierarchySearchString });
|
||||
@@ -84,21 +83,6 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
return AppUserData.template(offices, availableRoles);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<AppUserData> retrieveAllUsersWithRoles() {
|
||||
|
||||
final Collection<AppUser> users = this.appUserRepository.findAll();
|
||||
final Collection<AppUserData> appUserData = new HashSet<AppUserData>();
|
||||
for(final AppUser user : users){
|
||||
final Set<RoleData> selectedUserRoles = new HashSet<RoleData>();
|
||||
for(final Role role : user.getRoles()){
|
||||
selectedUserRoles.add(role.toData()) ;
|
||||
}
|
||||
appUserData.add(AppUserData.instance(user.getId(), user.getUsername(), user.getEmail(), user.getOffice().getId(),
|
||||
user.getOffice().getName(), user.getFirstname(), user.getLastname(),null,selectedUserRoles)) ;
|
||||
}
|
||||
return appUserData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AppUserData retrieveUser(final Long userId) {
|
||||
@@ -124,6 +108,11 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
|
||||
private static final class AppUserMapper implements RowMapper<AppUserData> {
|
||||
|
||||
private final RoleReadPlatformService roleReadPlatformService;
|
||||
|
||||
public AppUserMapper(final RoleReadPlatformService roleReadPlatformService){
|
||||
this.roleReadPlatformService = roleReadPlatformService;
|
||||
}
|
||||
@Override
|
||||
public AppUserData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
@@ -135,7 +124,10 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, null);
|
||||
//pass the client id to retrieve the clients assigned roles
|
||||
final Collection<RoleData> selectedRoles = this.roleReadPlatformService.retrieveClientRoles(id);
|
||||
|
||||
return AppUserData.instance(id, username, email, officeId, officeName, firstname, lastname, null, selectedRoles);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
|
||||
Regular → Executable
+4
-2
@@ -5,13 +5,15 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface RoleReadPlatformService {
|
||||
|
||||
Collection<RoleData> retrieveAll();
|
||||
|
||||
RoleData retrieveOne(Long roleId);
|
||||
|
||||
Collection<RoleData> retrieveClientRoles(Long clientId);
|
||||
}
|
||||
Regular → Executable
+12
-4
@@ -5,10 +5,6 @@
|
||||
*/
|
||||
package org.mifosplatform.useradministration.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosplatform.infrastructure.core.domain.JdbcSupport;
|
||||
import org.mifosplatform.infrastructure.core.service.RoutingDataSource;
|
||||
import org.mifosplatform.useradministration.data.RoleData;
|
||||
@@ -19,6 +15,10 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
|
||||
@Service
|
||||
public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
|
||||
@@ -66,4 +66,12 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
return " r.id as id, r.name as name, r.description as description from m_role r";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RoleData> retrieveClientRoles(Long clientId) {
|
||||
final String sql = "select " + this.roleRowMapper.schema() + " inner join m_appuser_role"
|
||||
+ " ar on ar.role_id = r.id where ar.appuser_id= ?";
|
||||
|
||||
return this.jdbcTemplate.query(sql,this.roleRowMapper,new Object[]{clientId});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user