MIFOSX-97: some tidy up around users,roles and permissions in prep for command work.
This commit is contained in:
+20
-19
@@ -25,28 +25,29 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class PermissionsApiResource {
|
||||
|
||||
@Autowired
|
||||
private PermissionReadPlatformService permissionReadPlatformService;
|
||||
@Autowired
|
||||
private PermissionReadPlatformService permissionReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
@Autowired
|
||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
private final String entityType = "PERMISSION";
|
||||
@Autowired
|
||||
private PlatformSecurityContext context;
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveAllPermissions(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<PermissionData> permissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions);
|
||||
}
|
||||
private final String resourceNameForPermissions = "PERMISSION";
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveAllPermissions(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
final Collection<PermissionData> permissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions);
|
||||
}
|
||||
}
|
||||
@@ -53,16 +53,17 @@ public class RolesApiResource {
|
||||
@Autowired
|
||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
private final String entityType = "ROLE";
|
||||
@Autowired
|
||||
private PlatformSecurityContext context;
|
||||
|
||||
private final String resourceNameForPermissions = "ROLE";
|
||||
|
||||
@GET
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveAllRoles(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
@@ -74,11 +75,11 @@ public class RolesApiResource {
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveNewRoleDetails(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
@@ -91,8 +92,8 @@ public class RolesApiResource {
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String createRole(final String jsonRequestBody) {
|
||||
|
||||
final RoleCommand command = this.apiDataConversionService.convertJsonToRoleCommand(null, jsonRequestBody);
|
||||
@@ -112,11 +113,11 @@ public class RolesApiResource {
|
||||
// into account the Object its looking at.
|
||||
@GET
|
||||
@Path("{roleId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveRole(@PathParam("roleId") final Long roleId, @Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
@@ -135,8 +136,8 @@ public class RolesApiResource {
|
||||
|
||||
@PUT
|
||||
@Path("{roleId}")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String updateRole(@PathParam("roleId") final Long roleId, final String jsonRequestBody) {
|
||||
|
||||
final RoleCommand command = this.apiDataConversionService.convertJsonToRoleCommand(roleId, jsonRequestBody);
|
||||
@@ -148,28 +149,27 @@ public class RolesApiResource {
|
||||
|
||||
@GET
|
||||
@Path("{roleId}/permissions")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveRolePermissions(@PathParam("roleId") final Long roleId, @Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
Collection<PermissionUsageData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
||||
RolePermissionsData permissionsData = new RolePermissionsData(role.getId(), role.getName(), role.getDescription(),
|
||||
permissionUsageData);
|
||||
|
||||
final RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||
final Collection<PermissionUsageData> permissionUsageData = this.permissionReadPlatformService.retrieveAllRolePermissions(roleId);
|
||||
|
||||
final RolePermissionsData permissionsData = role.toRolePermissionData(permissionUsageData);
|
||||
|
||||
return this.apiJsonSerializerService.serializeRolePermissionDataToJson(prettyPrint, responseParameters, permissionsData);
|
||||
}
|
||||
|
||||
|
||||
@PUT
|
||||
@Path("{roleId}/permissions")
|
||||
@Consumes({ MediaType.APPLICATION_JSON })
|
||||
@Produces({ MediaType.APPLICATION_JSON })
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String updateRolePermissions(@PathParam("roleId") final Long roleId, final String jsonRequestBody) {
|
||||
|
||||
final RolePermissionCommand command = this.apiDataConversionService.convertJsonToRolePermissionCommand(roleId, jsonRequestBody);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package org.mifosng.platform.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -41,134 +39,116 @@ import org.springframework.stereotype.Component;
|
||||
@Scope("singleton")
|
||||
public class UsersApiResource {
|
||||
|
||||
@Autowired
|
||||
private AppUserReadPlatformService appUserReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private OfficeReadPlatformService officeReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private AppUserWritePlatformService appUserWritePlatformService;
|
||||
@Autowired
|
||||
private AppUserReadPlatformService appUserReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private PortfolioApiDataConversionService apiDataConversionService;
|
||||
|
||||
@Autowired
|
||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
@Autowired
|
||||
private OfficeReadPlatformService officeReadPlatformService;
|
||||
|
||||
private final String entityType = "USER";
|
||||
@Autowired
|
||||
private PlatformSecurityContext context;
|
||||
@Autowired
|
||||
private AppUserWritePlatformService appUserWritePlatformService;
|
||||
|
||||
private static final Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username", "firstname", "lastname", "email", "selectedRoles"));
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveUsers(@Context final UriInfo uriInfo) {
|
||||
@Autowired
|
||||
private PortfolioApiDataConversionService apiDataConversionService;
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
@Autowired
|
||||
private PortfolioApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
Collection<AppUserData> users = this.appUserReadPlatformService.retrieveAllUsers();
|
||||
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, users);
|
||||
}
|
||||
@Autowired
|
||||
private PlatformSecurityContext context;
|
||||
|
||||
private final String resourceNameForPermissions = "USER";
|
||||
|
||||
@GET
|
||||
@Path("{userId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveUser(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) {
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveUsers(@Context final UriInfo uriInfo) {
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
|
||||
AppUserData user = this.appUserReadPlatformService.retrieveUser(userId);
|
||||
if (template) {
|
||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
user = new AppUserData(user, offices);
|
||||
addTemplateRelatedParameters(responseParameters);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
}
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
private void addTemplateRelatedParameters(final Set<String> responseParameters) {
|
||||
responseParameters.add("allowedOffices");
|
||||
responseParameters.add("availableRoles");
|
||||
}
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String newUserDetails(@Context final UriInfo uriInfo) {
|
||||
final Collection<AppUserData> users = this.appUserReadPlatformService.retrieveAllUsers();
|
||||
|
||||
context.authenticatedUser().validateHasReadPermission(entityType);
|
||||
|
||||
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
if (responseParameters.isEmpty()) {
|
||||
responseParameters.addAll(typicalResponseParameters);
|
||||
}
|
||||
addTemplateRelatedParameters(responseParameters);
|
||||
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
AppUserData user = this.appUserReadPlatformService.retrieveNewUserDetails();
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, users);
|
||||
}
|
||||
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
}
|
||||
@GET
|
||||
@Path("{userId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String retrieveUser(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) {
|
||||
|
||||
@POST
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response createUser(final String jsonRequestBody) {
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
UserCommand command = this.apiDataConversionService.convertJsonToUserCommand(null, jsonRequestBody);
|
||||
|
||||
Long userId = this.appUserWritePlatformService.createUser(command);
|
||||
return Response.ok().entity(new EntityIdentifier(userId)).build();
|
||||
}
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
final boolean template = ApiParameterHelper.template(uriInfo.getQueryParameters());
|
||||
|
||||
@DELETE
|
||||
@Path("{userId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response deleteUser(@PathParam("userId") final Long userId) {
|
||||
AppUserData user = this.appUserReadPlatformService.retrieveUser(userId);
|
||||
if (template) {
|
||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
user = new AppUserData(user, offices);
|
||||
}
|
||||
|
||||
this.appUserWritePlatformService.deleteUser(userId);
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
}
|
||||
|
||||
return Response.ok(new EntityIdentifier(userId)).build();
|
||||
}
|
||||
@GET
|
||||
@Path("template")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public String newUserDetails(@Context final UriInfo uriInfo) {
|
||||
|
||||
@PUT
|
||||
@Path("{userId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response updateUser(@PathParam("userId") final Long userId, final String jsonRequestBody) {
|
||||
context.authenticatedUser().validateHasReadPermission(resourceNameForPermissions);
|
||||
|
||||
UserCommand command = this.apiDataConversionService.convertJsonToUserCommand(userId, jsonRequestBody);
|
||||
final Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||
final boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
AppUser loggedInUser = context.authenticatedUser();
|
||||
|
||||
if (loggedInUser.hasIdOf(userId)) {
|
||||
this.appUserWritePlatformService.updateUsersOwnAccountDetails(command);
|
||||
} else {
|
||||
this.appUserWritePlatformService.updateUser(command);
|
||||
}
|
||||
final AppUserData user = this.appUserReadPlatformService.retrieveNewUserDetails();
|
||||
|
||||
return Response.ok().entity(new EntityIdentifier(userId)).build();
|
||||
}
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
}
|
||||
|
||||
@POST
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response createUser(final String jsonRequestBody) {
|
||||
|
||||
final UserCommand command = this.apiDataConversionService.convertJsonToUserCommand(null, jsonRequestBody);
|
||||
|
||||
final Long userId = this.appUserWritePlatformService.createUser(command);
|
||||
return Response.ok().entity(new EntityIdentifier(userId)).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@Path("{userId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response deleteUser(@PathParam("userId") final Long userId) {
|
||||
|
||||
this.appUserWritePlatformService.deleteUser(userId);
|
||||
|
||||
return Response.ok(new EntityIdentifier(userId)).build();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("{userId}")
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
public Response updateUser(@PathParam("userId") final Long userId, final String jsonRequestBody) {
|
||||
|
||||
final UserCommand command = this.apiDataConversionService.convertJsonToUserCommand(userId, jsonRequestBody);
|
||||
|
||||
final AppUser loggedInUser = context.authenticatedUser();
|
||||
|
||||
if (loggedInUser.hasIdOf(userId)) {
|
||||
this.appUserWritePlatformService.updateUsersOwnAccountDetails(command);
|
||||
} else {
|
||||
this.appUserWritePlatformService.updateUser(command);
|
||||
}
|
||||
|
||||
return Response.ok().entity(new EntityIdentifier(userId)).build();
|
||||
}
|
||||
}
|
||||
@@ -7,40 +7,36 @@ import java.util.Set;
|
||||
*/
|
||||
public class RoleCommand {
|
||||
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
private final Set<String> modifiedParameters;
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
public RoleCommand(Set<String> modifiedParameters, final Long id, final String name, final String description, final String[] permissionIds) {
|
||||
this.modifiedParameters = modifiedParameters;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
private final Set<String> modifiedParameters;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public RoleCommand(Set<String> modifiedParameters, final Long id, final String name, final String description) {
|
||||
this.modifiedParameters = modifiedParameters;
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean isNameChanged() {
|
||||
return this.modifiedParameters.contains("name");
|
||||
}
|
||||
|
||||
public boolean isDescriptionChanged() {
|
||||
return this.modifiedParameters.contains("description");
|
||||
}
|
||||
|
||||
public boolean isPermissionsChanged() {
|
||||
return this.modifiedParameters.contains("permissions");
|
||||
}
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isNameChanged() {
|
||||
return this.modifiedParameters.contains("name");
|
||||
}
|
||||
|
||||
public boolean isDescriptionChanged() {
|
||||
return this.modifiedParameters.contains("description");
|
||||
}
|
||||
}
|
||||
@@ -8,99 +8,67 @@ import java.util.List;
|
||||
*/
|
||||
public class AppUserData {
|
||||
|
||||
private final Long id;
|
||||
private final String username;
|
||||
private final Long officeId;
|
||||
private final String officeName;
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
private final String email;
|
||||
private final Long id;
|
||||
private final String username;
|
||||
private final Long officeId;
|
||||
private final String officeName;
|
||||
private final String firstname;
|
||||
private final String lastname;
|
||||
private final String email;
|
||||
|
||||
private final List<OfficeLookup> allowedOffices;
|
||||
private final List<RoleData> availableRoles;
|
||||
private final List<RoleData> selectedRoles;
|
||||
@SuppressWarnings("unused")
|
||||
private final List<OfficeLookup> allowedOffices;
|
||||
private final List<RoleData> availableRoles;
|
||||
private final List<RoleData> selectedRoles;
|
||||
|
||||
public AppUserData(final Long id, final String username,
|
||||
final String email, final Long officeId,
|
||||
final String officeName, final String firstname, final String lastname, final List<RoleData> availableRoles, final List<RoleData> selectedRoles) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.officeId = officeId;
|
||||
this.officeName = officeName;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.email = email;
|
||||
|
||||
this.allowedOffices = new ArrayList<OfficeLookup>();
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = selectedRoles;
|
||||
}
|
||||
|
||||
public AppUserData(AppUserData user, List<OfficeLookup> allowedOffices) {
|
||||
this.id = user.getId();
|
||||
this.username = user.getUsername();
|
||||
this.officeId = user.getOfficeId();
|
||||
this.officeName = user.getOfficeName();
|
||||
this.firstname = user.getFirstname();
|
||||
this.lastname = user.getLastname();
|
||||
this.email = user.getEmail();
|
||||
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = user.getAvailableRoles();
|
||||
this.selectedRoles = user.getSelectedRoles();
|
||||
}
|
||||
public AppUserData(final Long id, final String username, final String email, final Long officeId, final String officeName,
|
||||
final String firstname, final String lastname, final List<RoleData> availableRoles, final List<RoleData> selectedRoles) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.officeId = officeId;
|
||||
this.officeName = officeName;
|
||||
this.firstname = firstname;
|
||||
this.lastname = lastname;
|
||||
this.email = email;
|
||||
|
||||
public AppUserData(final List<OfficeLookup> allowedOffices, final List<RoleData> availableRoles) {
|
||||
this.id = null;
|
||||
this.username = null;
|
||||
this.officeId = null;
|
||||
this.officeName = null;
|
||||
this.firstname = null;
|
||||
this.lastname = null;
|
||||
this.email = null;
|
||||
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = new ArrayList<RoleData>();
|
||||
}
|
||||
this.allowedOffices = new ArrayList<OfficeLookup>();
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = selectedRoles;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public AppUserData(final AppUserData user, final List<OfficeLookup> allowedOffices) {
|
||||
this.id = user.id;
|
||||
this.username = user.username;
|
||||
this.officeId = user.officeId;
|
||||
this.officeName = user.officeName;
|
||||
this.firstname = user.firstname;
|
||||
this.lastname = user.lastname;
|
||||
this.email = user.email;
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = user.availableRoles;
|
||||
this.selectedRoles = user.selectedRoles;
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return officeId;
|
||||
}
|
||||
public AppUserData(final List<OfficeLookup> allowedOffices, final List<RoleData> availableRoles) {
|
||||
this.id = null;
|
||||
this.username = null;
|
||||
this.officeId = null;
|
||||
this.officeName = null;
|
||||
this.firstname = null;
|
||||
this.lastname = null;
|
||||
this.email = null;
|
||||
|
||||
public String getOfficeName() {
|
||||
return officeName;
|
||||
}
|
||||
this.allowedOffices = allowedOffices;
|
||||
this.availableRoles = availableRoles;
|
||||
this.selectedRoles = new ArrayList<RoleData>();
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
public boolean hasIdentifyOf(final Long createdById) {
|
||||
return this.id.equals(createdById);
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public List<OfficeLookup> getAllowedOffices() {
|
||||
return allowedOffices;
|
||||
}
|
||||
|
||||
public List<RoleData> getAvailableRoles() {
|
||||
return availableRoles;
|
||||
}
|
||||
|
||||
public List<RoleData> getSelectedRoles() {
|
||||
return selectedRoles;
|
||||
}
|
||||
public String username() {
|
||||
return this.username;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,23 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
/**
|
||||
* Immutable data object used for office lookups (will remove eventually and just use {@link OfficeData}.
|
||||
*/
|
||||
public class OfficeLookup {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String nameDecorated;
|
||||
private Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
@SuppressWarnings("unused")
|
||||
private String nameDecorated;
|
||||
|
||||
public OfficeLookup(final Long id, final String name, final String nameDecorated) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.nameDecorated = nameDecorated;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String getNameDecorated() {
|
||||
return nameDecorated;
|
||||
}
|
||||
public OfficeLookup(final Long id, final String name, final String nameDecorated) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.nameDecorated = nameDecorated;
|
||||
}
|
||||
|
||||
public boolean hasIdentifyOf(final Long officeId) {
|
||||
return this.id.equals(officeId);
|
||||
}
|
||||
}
|
||||
@@ -5,29 +5,29 @@ package org.mifosng.platform.api.data;
|
||||
*/
|
||||
public class PermissionData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
private final String code;
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
private final String code;
|
||||
|
||||
public PermissionData(final Long id, final String name, final String description, final String code) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.code = code;
|
||||
}
|
||||
public PermissionData(final Long id, final String name, final String description, final String code) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
PermissionData data = (PermissionData) obj;
|
||||
return this.code.equalsIgnoreCase(data.code);
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
PermissionData data = (PermissionData) obj;
|
||||
return this.code.equalsIgnoreCase(data.code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.code.hashCode();
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.code.hashCode();
|
||||
}
|
||||
}
|
||||
+8
-21
@@ -1,11 +1,19 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
/**
|
||||
* Immutable representation of permissions
|
||||
*/
|
||||
public class PermissionUsageData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final String grouping;
|
||||
@SuppressWarnings("unused")
|
||||
private final String code;
|
||||
@SuppressWarnings("unused")
|
||||
private final String entityName;
|
||||
@SuppressWarnings("unused")
|
||||
private final String actionName;
|
||||
@SuppressWarnings("unused")
|
||||
private final Boolean selected;
|
||||
|
||||
public PermissionUsageData(final String grouping, final String code, final String entityName, final String actionName,
|
||||
@@ -16,25 +24,4 @@ public class PermissionUsageData {
|
||||
this.actionName = actionName;
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
public String getGrouping() {
|
||||
return grouping;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getEntityName() {
|
||||
return entityName;
|
||||
}
|
||||
|
||||
public String getActionName() {
|
||||
return actionName;
|
||||
}
|
||||
|
||||
public Boolean getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,70 +8,62 @@ import java.util.Collection;
|
||||
*/
|
||||
public class RoleData {
|
||||
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionData> availablePermissions;
|
||||
private final Collection<PermissionData> selectedPermissions;
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
public RoleData(final Long id, final String name, final String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.availablePermissions = null;
|
||||
this.selectedPermissions = null;
|
||||
}
|
||||
|
||||
public RoleData(final Long id, final String name, final String description, final Collection<PermissionData> selectedPermissions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.availablePermissions = null;
|
||||
this.selectedPermissions = selectedPermissions;
|
||||
}
|
||||
public RoleData(final Collection<PermissionData> availablePermissions, final Collection<PermissionData> selectedPermissions) {
|
||||
this.id = null;
|
||||
this.name = null;
|
||||
this.description = null;
|
||||
this.availablePermissions = new ArrayList<PermissionData>(availablePermissions);
|
||||
this.selectedPermissions = new ArrayList<PermissionData>(selectedPermissions);
|
||||
}
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionData> availablePermissions;
|
||||
private final Collection<PermissionData> selectedPermissions;
|
||||
|
||||
public RoleData(final RoleData role, final Collection<PermissionData> availablePermissions) {
|
||||
this.id = role.id;
|
||||
this.name = role.name;
|
||||
this.description = role.description;
|
||||
this.availablePermissions = availablePermissions;
|
||||
this.selectedPermissions = role.selectedPermissions;
|
||||
}
|
||||
public RoleData(final Long id, final String name, final String description) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.availablePermissions = null;
|
||||
this.selectedPermissions = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
final RoleData role = (RoleData) obj;
|
||||
return this.id.equals(role.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
public RoleData(final Long id, final String name, final String description, final Collection<PermissionData> selectedPermissions) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.availablePermissions = null;
|
||||
this.selectedPermissions = selectedPermissions;
|
||||
}
|
||||
|
||||
public Collection<PermissionData> selectedPermissions() {
|
||||
return this.selectedPermissions;
|
||||
}
|
||||
public RoleData(final Collection<PermissionData> availablePermissions, final Collection<PermissionData> selectedPermissions) {
|
||||
this.id = null;
|
||||
this.name = null;
|
||||
this.description = null;
|
||||
this.availablePermissions = new ArrayList<PermissionData>(availablePermissions);
|
||||
this.selectedPermissions = new ArrayList<PermissionData>(selectedPermissions);
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public RoleData(final RoleData role, final Collection<PermissionData> availablePermissions) {
|
||||
this.id = role.id;
|
||||
this.name = role.name;
|
||||
this.description = role.description;
|
||||
this.availablePermissions = availablePermissions;
|
||||
this.selectedPermissions = role.selectedPermissions;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(final Object obj) {
|
||||
final RoleData role = (RoleData) obj;
|
||||
return this.id.equals(role.id);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id.hashCode();
|
||||
}
|
||||
|
||||
public Collection<PermissionData> selectedPermissions() {
|
||||
return this.selectedPermissions;
|
||||
}
|
||||
|
||||
public RolePermissionsData toRolePermissionData(final Collection<PermissionUsageData> permissionUsageData) {
|
||||
return new RolePermissionsData(id, name, description, permissionUsageData);
|
||||
}
|
||||
}
|
||||
+7
-17
@@ -2,12 +2,19 @@ package org.mifosng.platform.api.data;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Immutable data object reprsenting a role with associated permissions.
|
||||
*/
|
||||
public class RolePermissionsData {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Long id;
|
||||
@SuppressWarnings("unused")
|
||||
private final String name;
|
||||
@SuppressWarnings("unused")
|
||||
private final String description;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private final Collection<PermissionUsageData> permissionUsageData;
|
||||
|
||||
public RolePermissionsData(final Long id, final String name, final String description,
|
||||
@@ -17,21 +24,4 @@ public class RolePermissionsData {
|
||||
this.description = description;
|
||||
this.permissionUsageData = permissionUsageData;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public Collection<PermissionUsageData> getPermissionUsageData() {
|
||||
return permissionUsageData;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-19
@@ -241,28 +241,10 @@ public class PortfolioApiDataConversionServiceImpl implements PortfolioApiDataCo
|
||||
|
||||
Set<String> modifiedParameters = new HashSet<String>();
|
||||
|
||||
// check array
|
||||
JsonParser parser = new JsonParser();
|
||||
|
||||
String[] permissionIds = null;
|
||||
JsonElement element = parser.parse(json);
|
||||
if (element.isJsonObject()) {
|
||||
JsonObject object = element.getAsJsonObject();
|
||||
if (object.has("permissions")) {
|
||||
modifiedParameters.add("permissions");
|
||||
JsonArray array = object.get("permissions").getAsJsonArray();
|
||||
permissionIds = new String[array.size()];
|
||||
for (int i = 0; i < array.size(); i++) {
|
||||
permissionIds[i] = array.get(i).getAsString();
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
|
||||
String name = extractStringParameter("name", requestMap, modifiedParameters);
|
||||
String description = extractStringParameter("description", requestMap, modifiedParameters);
|
||||
|
||||
return new RoleCommand(modifiedParameters, resourceIdentifier, name, description, permissionIds);
|
||||
return new RoleCommand(modifiedParameters, resourceIdentifier, name, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+331
-368
@@ -37,59 +37,56 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class ClientReadPlatformServiceImpl implements ClientReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final AppUserReadPlatformService appUserReadPlatformService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final OfficeReadPlatformService officeReadPlatformService;
|
||||
private final AppUserReadPlatformService appUserReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
public ClientReadPlatformServiceImpl(final PlatformSecurityContext context,
|
||||
final TenantAwareRoutingDataSource dataSource,
|
||||
final OfficeReadPlatformService officeReadPlatformService,
|
||||
final AppUserReadPlatformService appUserReadPlatformService) {
|
||||
this.context = context;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.appUserReadPlatformService = appUserReadPlatformService;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
@Autowired
|
||||
public ClientReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||
final OfficeReadPlatformService officeReadPlatformService, final AppUserReadPlatformService appUserReadPlatformService) {
|
||||
this.context = context;
|
||||
this.officeReadPlatformService = officeReadPlatformService;
|
||||
this.appUserReadPlatformService = appUserReadPlatformService;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ClientData> retrieveAllIndividualClients(final String extraCriteria) {
|
||||
@Override
|
||||
public Collection<ClientData> retrieveAllIndividualClients(final String extraCriteria) {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
ClientMapper rm = new ClientMapper();
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
String sql = "select " + rm.clientSchema();
|
||||
ClientMapper rm = new ClientMapper();
|
||||
|
||||
if (StringUtils.isNotBlank(extraCriteria))
|
||||
sql += " and (" + extraCriteria + ")";
|
||||
String sql = "select " + rm.clientSchema();
|
||||
|
||||
sql += " order by c.lastname ASC, c.firstname ASC";
|
||||
if (StringUtils.isNotBlank(extraCriteria)) sql += " and (" + extraCriteria + ")";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {hierarchySearchString});
|
||||
}
|
||||
sql += " order by c.lastname ASC, c.firstname ASC";
|
||||
|
||||
@Override
|
||||
public ClientData retrieveIndividualClient(final Long clientId) {
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
try {
|
||||
@Override
|
||||
public ClientData retrieveIndividualClient(final Long clientId) {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
ClientMapper rm = new ClientMapper();
|
||||
try {
|
||||
|
||||
String sql = "select " + rm.clientSchema() + " and c.id = " + clientId;
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] {hierarchySearchString});
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
}
|
||||
ClientMapper rm = new ClientMapper();
|
||||
|
||||
String sql = "select " + rm.clientSchema() + " and c.id = " + clientId;
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, rm, new Object[] { hierarchySearchString });
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ClientLookup> retrieveAllIndividualClientsForLookup(String extraCriteria) {
|
||||
@@ -100,7 +97,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
|
||||
String sql = "select " + rm.clientLookupSchema();
|
||||
|
||||
if (StringUtils.isNotBlank(extraCriteria)){
|
||||
if (StringUtils.isNotBlank(extraCriteria)) {
|
||||
sql += " and (" + extraCriteria + ")";
|
||||
}
|
||||
|
||||
@@ -119,57 +116,53 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientData retrieveNewClientDetails() {
|
||||
public ClientData retrieveNewClientDetails() {
|
||||
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
final AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
final List<OfficeLookup> offices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
final Long officeId = currentUser.getOffice().getId();
|
||||
|
||||
return ClientData.template(officeId, new LocalDate(), offices);
|
||||
}
|
||||
final List<OfficeLookup> offices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
final Long officeId = currentUser.getOffice().getId();
|
||||
|
||||
return ClientData.template(officeId, new LocalDate(), offices);
|
||||
}
|
||||
|
||||
private static final class ClientMapper implements RowMapper<ClientData> {
|
||||
|
||||
private static final class ClientMapper implements RowMapper<ClientData> {
|
||||
public String clientSchema() {
|
||||
return "c.office_id as officeId, o.name as officeName, c.id as id, c.firstname as firstname, c.lastname as lastname, c.display_name as displayName, "
|
||||
+ "c.external_id as externalId, c.joining_date as joinedDate, c.image_key as imagekey from m_client c join m_office o on o.id = c.office_id "
|
||||
+ " where o.hierarchy like ? and c.is_deleted=0 ";
|
||||
}
|
||||
|
||||
public String clientSchema() {
|
||||
return "c.office_id as officeId, o.name as officeName, c.id as id, c.firstname as firstname, c.lastname as lastname, c.display_name as displayName, " +
|
||||
"c.external_id as externalId, c.joining_date as joinedDate, c.image_key as imagekey from m_client c join m_office o on o.id = c.office_id " +
|
||||
" where o.hierarchy like ? and c.is_deleted=0 ";
|
||||
}
|
||||
@Override
|
||||
public ClientData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
@Override
|
||||
public ClientData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
String firstname = rs.getString("firstname");
|
||||
if (StringUtils.isBlank(firstname)) {
|
||||
firstname = "";
|
||||
}
|
||||
final String lastname = rs.getString("lastname");
|
||||
final String displayName = rs.getString("displayName");
|
||||
final String externalId = rs.getString("externalId");
|
||||
final LocalDate joinedDate = JdbcSupport.getLocalDate(rs, "joinedDate");
|
||||
final String imageKey = rs.getString("imageKey");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
final Long officeId = JdbcSupport.getLong(rs, "officeId");
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
String firstname = rs.getString("firstname");
|
||||
if (StringUtils.isBlank(firstname)) {
|
||||
firstname = "";
|
||||
}
|
||||
final String lastname = rs.getString("lastname");
|
||||
final String displayName = rs.getString("displayName");
|
||||
final String externalId = rs.getString("externalId");
|
||||
final LocalDate joinedDate = JdbcSupport.getLocalDate(rs, "joinedDate");
|
||||
final String imageKey = rs.getString("imageKey");
|
||||
final String officeName = rs.getString("officeName");
|
||||
return new ClientData(officeId, officeName, id, firstname, lastname, displayName, externalId, joinedDate, imageKey, null, null,
|
||||
null);
|
||||
}
|
||||
|
||||
return new ClientData(officeId, officeName, id, firstname,
|
||||
lastname, displayName, externalId, joinedDate,imageKey, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final class ClientLookupMapper implements RowMapper<ClientLookup>{
|
||||
private static final class ClientLookupMapper implements RowMapper<ClientLookup> {
|
||||
|
||||
public String clientLookupSchema() {
|
||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname, " +
|
||||
"c.office_id as officeId, o.name as officeName " +
|
||||
"from m_client c join m_office o on o.id = c.office_id where c.is_deleted=0 ";
|
||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname, " + "c.office_id as officeId, o.name as officeName "
|
||||
+ "from m_client c join m_office o on o.id = c.office_id where c.is_deleted=0 ";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ClientLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
Long id = rs.getLong("id");
|
||||
@@ -186,82 +179,83 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientAccountSummaryCollectionData retrieveClientAccountDetails(final Long clientId) {
|
||||
@Override
|
||||
public ClientAccountSummaryCollectionData retrieveClientAccountDetails(final Long clientId) {
|
||||
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
// Check if client exists
|
||||
retrieveIndividualClient(clientId);
|
||||
try {
|
||||
this.context.authenticatedUser();
|
||||
|
||||
List<ClientAccountSummaryData> pendingApprovalLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> awaitingDisbursalLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> openLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> closedLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
// Check if client exists
|
||||
retrieveIndividualClient(clientId);
|
||||
|
||||
ClientLoanAccountSummaryDataMapper rm = new ClientLoanAccountSummaryDataMapper();
|
||||
List<ClientAccountSummaryData> pendingApprovalLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> awaitingDisbursalLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> openLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> closedLoans = new ArrayList<ClientAccountSummaryData>();
|
||||
|
||||
String sql = "select " + rm.loanAccountSummarySchema() + " where l.client_id = ?";
|
||||
ClientLoanAccountSummaryDataMapper rm = new ClientLoanAccountSummaryDataMapper();
|
||||
|
||||
List<ClientAccountSummaryData> results = this.jdbcTemplate.query(sql, rm, new Object[] {clientId});
|
||||
if (results != null) {
|
||||
for (ClientAccountSummaryData row : results) {
|
||||
String sql = "select " + rm.loanAccountSummarySchema() + " where l.client_id = ?";
|
||||
|
||||
LoanStatusMapper statusMapper = new LoanStatusMapper(row.getAccountStatusId());
|
||||
List<ClientAccountSummaryData> results = this.jdbcTemplate.query(sql, rm, new Object[] { clientId });
|
||||
if (results != null) {
|
||||
for (ClientAccountSummaryData row : results) {
|
||||
|
||||
if (statusMapper.isOpen()) {
|
||||
openLoans.add(row);
|
||||
} else if (statusMapper.isAwaitingDisbursal()) {
|
||||
awaitingDisbursalLoans.add(row);
|
||||
} else if (statusMapper.isPendingApproval()) {
|
||||
pendingApprovalLoans.add(row);
|
||||
} else {
|
||||
closedLoans.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<ClientAccountSummaryData> pendingApprovalDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> approvedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> withdrawnByClientDespositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> closedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> rejectedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> preclosedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> maturedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
|
||||
ClientDespoitAccountSummaryDataMapper depositAccountMapper = new ClientDespoitAccountSummaryDataMapper();
|
||||
LoanStatusMapper statusMapper = new LoanStatusMapper(row.getAccountStatusId());
|
||||
|
||||
String depositAccountsSql = "select " + depositAccountMapper.schema() + " where da.client_id = ? and da.is_deleted=0";
|
||||
List<ClientAccountSummaryData> depositAccountResults = this.jdbcTemplate.query(depositAccountsSql, depositAccountMapper, new Object[] {clientId});
|
||||
if (depositAccountResults != null) {
|
||||
for (ClientAccountSummaryData row : depositAccountResults) {
|
||||
if (statusMapper.isOpen()) {
|
||||
openLoans.add(row);
|
||||
} else if (statusMapper.isAwaitingDisbursal()) {
|
||||
awaitingDisbursalLoans.add(row);
|
||||
} else if (statusMapper.isPendingApproval()) {
|
||||
pendingApprovalLoans.add(row);
|
||||
} else {
|
||||
closedLoans.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (row.getAccountStatusId() == 100) {
|
||||
pendingApprovalDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 300) {
|
||||
approvedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 400) {
|
||||
withdrawnByClientDespositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 500) {
|
||||
rejectedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 600) {
|
||||
closedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 700) {
|
||||
maturedDepositAccounts.add(row);
|
||||
}else if (row.getAccountStatusId() == 800) {
|
||||
preclosedDepositAccounts.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
List<ClientAccountSummaryData> pendingApprovalDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> approvedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> withdrawnByClientDespositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> closedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> rejectedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> preclosedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
List<ClientAccountSummaryData> maturedDepositAccounts = new ArrayList<ClientAccountSummaryData>();
|
||||
|
||||
return new ClientAccountSummaryCollectionData(pendingApprovalLoans, awaitingDisbursalLoans, openLoans, closedLoans,
|
||||
pendingApprovalDepositAccounts, approvedDepositAccounts, withdrawnByClientDespositAccounts,
|
||||
rejectedDepositAccounts,closedDepositAccounts,preclosedDepositAccounts,maturedDepositAccounts);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
}
|
||||
ClientDespoitAccountSummaryDataMapper depositAccountMapper = new ClientDespoitAccountSummaryDataMapper();
|
||||
|
||||
String depositAccountsSql = "select " + depositAccountMapper.schema() + " where da.client_id = ? and da.is_deleted=0";
|
||||
List<ClientAccountSummaryData> depositAccountResults = this.jdbcTemplate.query(depositAccountsSql, depositAccountMapper,
|
||||
new Object[] { clientId });
|
||||
if (depositAccountResults != null) {
|
||||
for (ClientAccountSummaryData row : depositAccountResults) {
|
||||
|
||||
if (row.getAccountStatusId() == 100) {
|
||||
pendingApprovalDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 300) {
|
||||
approvedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 400) {
|
||||
withdrawnByClientDespositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 500) {
|
||||
rejectedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 600) {
|
||||
closedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 700) {
|
||||
maturedDepositAccounts.add(row);
|
||||
} else if (row.getAccountStatusId() == 800) {
|
||||
preclosedDepositAccounts.add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ClientAccountSummaryCollectionData(pendingApprovalLoans, awaitingDisbursalLoans, openLoans, closedLoans,
|
||||
pendingApprovalDepositAccounts, approvedDepositAccounts, withdrawnByClientDespositAccounts, rejectedDepositAccounts,
|
||||
closedDepositAccounts, preclosedDepositAccounts, maturedDepositAccounts);
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientNotFoundException(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ClientAccountSummaryData> retrieveClientLoanAccountsByLoanOfficerId(Long clientId, Long loanOfficerId) {
|
||||
@@ -275,282 +269,251 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService
|
||||
|
||||
String sql = "select " + rm.loanAccountSummarySchema() + " where l.client_id = ? and l.loan_officer_id = ?";
|
||||
|
||||
List<ClientAccountSummaryData> loanAccounts = this.jdbcTemplate.query(sql, rm, new Object[] {clientId, loanOfficerId});
|
||||
List<ClientAccountSummaryData> loanAccounts = this.jdbcTemplate.query(sql, rm, new Object[] { clientId, loanOfficerId });
|
||||
|
||||
return loanAccounts;
|
||||
}
|
||||
|
||||
private static final class ClientLoanAccountSummaryDataMapper implements
|
||||
RowMapper<ClientAccountSummaryData> {
|
||||
private static final class ClientLoanAccountSummaryDataMapper implements RowMapper<ClientAccountSummaryData> {
|
||||
|
||||
public String loanAccountSummarySchema() {
|
||||
public String loanAccountSummarySchema() {
|
||||
|
||||
StringBuilder accountsSummary = new StringBuilder("l.id as id, l.external_id as externalId,");
|
||||
accountsSummary
|
||||
.append("l.product_id as productId, lp.name as productName,")
|
||||
.append("l.loan_status_id as statusId ")
|
||||
.append("from m_loan l ")
|
||||
.append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id ");
|
||||
StringBuilder accountsSummary = new StringBuilder("l.id as id, l.external_id as externalId,");
|
||||
accountsSummary.append("l.product_id as productId, lp.name as productName,").append("l.loan_status_id as statusId ")
|
||||
.append("from m_loan l ").append("LEFT JOIN m_product_loan AS lp ON lp.id = l.product_id ");
|
||||
|
||||
return accountsSummary.toString();
|
||||
}
|
||||
return accountsSummary.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientAccountSummaryData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
@Override
|
||||
public ClientAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
String externalId = rs.getString("externalId");
|
||||
Long productId = JdbcSupport.getLong(rs, "productId");
|
||||
String loanProductName = rs.getString("productName");
|
||||
Integer loanStatusId = JdbcSupport.getInteger(rs, "statusId");
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
String externalId = rs.getString("externalId");
|
||||
Long productId = JdbcSupport.getLong(rs, "productId");
|
||||
String loanProductName = rs.getString("productName");
|
||||
Integer loanStatusId = JdbcSupport.getInteger(rs, "statusId");
|
||||
|
||||
return new ClientAccountSummaryData(id, externalId, productId, loanProductName, loanStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ClientDespoitAccountSummaryDataMapper implements RowMapper<ClientAccountSummaryData> {
|
||||
return new ClientAccountSummaryData(id, externalId, productId, loanProductName, loanStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
|
||||
StringBuilder accountsSummary = new StringBuilder("da.id as id, da.external_id as externalId,");
|
||||
accountsSummary.append("da.product_id as productId, dp.name as productName,")
|
||||
.append("da.status_enum as statusId ")
|
||||
.append("from m_deposit_account da ")
|
||||
.append("LEFT JOIN m_product_deposit AS dp ON dp.id = da.product_id ");
|
||||
|
||||
return accountsSummary.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientAccountSummaryData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
String externalId = rs.getString("externalId");
|
||||
Long productId = JdbcSupport.getLong(rs, "productId");
|
||||
String productName = rs.getString("productName");
|
||||
Integer accountStatusId = JdbcSupport.getInteger(rs, "statusId");
|
||||
|
||||
return new ClientAccountSummaryData(id, externalId, productId, productName, accountStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static final class ClientDespoitAccountSummaryDataMapper implements RowMapper<ClientAccountSummaryData> {
|
||||
|
||||
@Override
|
||||
public NoteData retrieveClientNote(Long clientId, Long noteId) {
|
||||
public String schema() {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
// Check if client exists
|
||||
retrieveIndividualClient(clientId);
|
||||
StringBuilder accountsSummary = new StringBuilder("da.id as id, da.external_id as externalId,");
|
||||
accountsSummary.append("da.product_id as productId, dp.name as productName,").append("da.status_enum as statusId ")
|
||||
.append("from m_deposit_account da ").append("LEFT JOIN m_product_deposit AS dp ON dp.id = da.product_id ");
|
||||
|
||||
// FIXME - use join on sql query to fetch user information for note
|
||||
// rather than fetching users?
|
||||
Collection<AppUserData> allUsers = this.appUserReadPlatformService
|
||||
.retrieveAllUsers();
|
||||
return accountsSummary.toString();
|
||||
}
|
||||
|
||||
NoteMapper noteMapper = new NoteMapper(allUsers);
|
||||
@Override
|
||||
public ClientAccountSummaryData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
String sql = "select " + noteMapper.schema()
|
||||
+ " where n.client_id = ? and n.id = ?";
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
String externalId = rs.getString("externalId");
|
||||
Long productId = JdbcSupport.getLong(rs, "productId");
|
||||
String productName = rs.getString("productName");
|
||||
Integer accountStatusId = JdbcSupport.getInteger(rs, "statusId");
|
||||
|
||||
return this.jdbcTemplate.queryForObject(sql, noteMapper, new Object[] {clientId, noteId});
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new NoteNotFoundException(clientId);
|
||||
}
|
||||
}
|
||||
return new ClientAccountSummaryData(id, externalId, productId, productName, accountStatusId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<NoteData> retrieveAllClientNotes(Long clientId) {
|
||||
@Override
|
||||
public NoteData retrieveClientNote(Long clientId, Long noteId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
// Check if client exists
|
||||
retrieveIndividualClient(clientId);
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
// FIXME - use join on sql query to fetch user information for note
|
||||
// rather than fetching users?
|
||||
Collection<AppUserData> allUsers = this.appUserReadPlatformService
|
||||
.retrieveAllUsers();
|
||||
// Check if client exists
|
||||
retrieveIndividualClient(clientId);
|
||||
|
||||
NoteMapper noteMapper = new NoteMapper(allUsers);
|
||||
// FIXME - use join on sql query to fetch user information for note
|
||||
// rather than fetching users?
|
||||
Collection<AppUserData> allUsers = this.appUserReadPlatformService.retrieveAllUsers();
|
||||
|
||||
String sql = "select "
|
||||
+ noteMapper.schema()
|
||||
+ " where n.client_id = ? order by n.created_date DESC";
|
||||
NoteMapper noteMapper = new NoteMapper(allUsers);
|
||||
|
||||
return this.jdbcTemplate.query(sql, noteMapper, new Object[] {clientId});
|
||||
}
|
||||
String sql = "select " + noteMapper.schema() + " where n.client_id = ? and n.id = ?";
|
||||
|
||||
private static final class NoteMapper implements RowMapper<NoteData> {
|
||||
return this.jdbcTemplate.queryForObject(sql, noteMapper, new Object[] { clientId, noteId });
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new NoteNotFoundException(clientId);
|
||||
}
|
||||
}
|
||||
|
||||
private final Collection<AppUserData> allUsers;
|
||||
@Override
|
||||
public Collection<NoteData> retrieveAllClientNotes(Long clientId) {
|
||||
|
||||
public NoteMapper(Collection<AppUserData> allUsers) {
|
||||
this.allUsers = allUsers;
|
||||
}
|
||||
context.authenticatedUser();
|
||||
|
||||
public String schema() {
|
||||
return "n.id as id, n.client_id as clientId, n.loan_id as loanId, n.loan_transaction_id as transactionId, n.note_type_enum as noteTypeEnum, n.note as note, "
|
||||
+ "n.created_date as createdDate, n.createdby_id as createdById, n.lastmodified_date as lastModifiedDate, n.lastmodifiedby_id as lastModifiedById"
|
||||
+ " from m_note n";
|
||||
}
|
||||
// Check if client exists
|
||||
retrieveIndividualClient(clientId);
|
||||
|
||||
@Override
|
||||
public NoteData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
// FIXME - use join on sql query to fetch user information for note
|
||||
// rather than fetching users?
|
||||
Collection<AppUserData> allUsers = this.appUserReadPlatformService.retrieveAllUsers();
|
||||
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
Long clientId = JdbcSupport.getLong(rs, "clientId");
|
||||
Long loanId = JdbcSupport.getLong(rs, "loanId");
|
||||
Long transactionId = JdbcSupport.getLong(rs, "transactionId");
|
||||
Integer noteTypeId = JdbcSupport.getInteger(rs, "noteTypeEnum");
|
||||
EnumOptionData noteType = NoteEnumerations.noteType(noteTypeId);
|
||||
String note = rs.getString("note");
|
||||
NoteMapper noteMapper = new NoteMapper(allUsers);
|
||||
|
||||
DateTime createdDate = JdbcSupport.getDateTime(rs, "createdDate");
|
||||
Long createdById = JdbcSupport.getLong(rs, "createdById");
|
||||
String createdByUsername = findUserById(createdById, allUsers);
|
||||
String sql = "select " + noteMapper.schema() + " where n.client_id = ? order by n.created_date DESC";
|
||||
|
||||
DateTime lastModifiedDate = JdbcSupport.getDateTime(rs,
|
||||
"lastModifiedDate");
|
||||
Long lastModifiedById = JdbcSupport.getLong(rs, "lastModifiedById");
|
||||
String updatedByUsername = findUserById(createdById, allUsers);
|
||||
return this.jdbcTemplate.query(sql, noteMapper, new Object[] { clientId });
|
||||
}
|
||||
|
||||
return new NoteData(id, clientId, loanId, transactionId, noteType,
|
||||
note, createdDate, createdById, createdByUsername,
|
||||
lastModifiedDate, lastModifiedById, updatedByUsername);
|
||||
}
|
||||
private static final class NoteMapper implements RowMapper<NoteData> {
|
||||
|
||||
private String findUserById(Long createdById, Collection<AppUserData> allUsers) {
|
||||
String username = "";
|
||||
for (AppUserData appUserData : allUsers) {
|
||||
if (appUserData.getId().equals(createdById)) {
|
||||
username = appUserData.getUsername();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return username;
|
||||
}
|
||||
}
|
||||
private final Collection<AppUserData> allUsers;
|
||||
|
||||
@Override
|
||||
public Collection<ClientIdentifierData> retrieveClientIdentifiers(final Long clientId) {
|
||||
public NoteMapper(Collection<AppUserData> allUsers) {
|
||||
this.allUsers = allUsers;
|
||||
}
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
public String schema() {
|
||||
return "n.id as id, n.client_id as clientId, n.loan_id as loanId, n.loan_transaction_id as transactionId, n.note_type_enum as noteTypeEnum, n.note as note, "
|
||||
+ "n.created_date as createdDate, n.createdby_id as createdById, n.lastmodified_date as lastModifiedDate, n.lastmodifiedby_id as lastModifiedById"
|
||||
+ " from m_note n";
|
||||
}
|
||||
|
||||
ClientIdentityMapper rm = new ClientIdentityMapper();
|
||||
@Override
|
||||
public NoteData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
String sql = "select " + rm.schema();
|
||||
Long id = JdbcSupport.getLong(rs, "id");
|
||||
Long clientId = JdbcSupport.getLong(rs, "clientId");
|
||||
Long loanId = JdbcSupport.getLong(rs, "loanId");
|
||||
Long transactionId = JdbcSupport.getLong(rs, "transactionId");
|
||||
Integer noteTypeId = JdbcSupport.getInteger(rs, "noteTypeEnum");
|
||||
EnumOptionData noteType = NoteEnumerations.noteType(noteTypeId);
|
||||
String note = rs.getString("note");
|
||||
|
||||
sql += " order by ci.id";
|
||||
DateTime createdDate = JdbcSupport.getDateTime(rs, "createdDate");
|
||||
Long createdById = JdbcSupport.getLong(rs, "createdById");
|
||||
String createdByUsername = findUserById(createdById, allUsers);
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { clientId, hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientIdentifierData retrieveClientIdentifier(
|
||||
final Long clientId,
|
||||
final Long clientIdentifierId) {
|
||||
try {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
DateTime lastModifiedDate = JdbcSupport.getDateTime(rs, "lastModifiedDate");
|
||||
Long lastModifiedById = JdbcSupport.getLong(rs, "lastModifiedById");
|
||||
String updatedByUsername = findUserById(createdById, allUsers);
|
||||
|
||||
ClientIdentityMapper rm = new ClientIdentityMapper();
|
||||
return new NoteData(id, clientId, loanId, transactionId, noteType, note, createdDate, createdById, createdByUsername,
|
||||
lastModifiedDate, lastModifiedById, updatedByUsername);
|
||||
}
|
||||
|
||||
String sql = "select " + rm.schema();
|
||||
private String findUserById(final Long createdById, final Collection<AppUserData> allUsers) {
|
||||
String username = "";
|
||||
for (AppUserData appUserData : allUsers) {
|
||||
if (appUserData.hasIdentifyOf(createdById)) {
|
||||
username = appUserData.username();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return username;
|
||||
}
|
||||
}
|
||||
|
||||
sql += " and ci.id = ?";
|
||||
@Override
|
||||
public Collection<ClientIdentifierData> retrieveClientIdentifiers(final Long clientId) {
|
||||
|
||||
final ClientIdentifierData clientIdentifierData = this.jdbcTemplate
|
||||
.queryForObject(sql, rm, new Object[] { clientId,
|
||||
hierarchySearchString, clientIdentifierId });
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
return clientIdentifierData;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientIdentifierNotFoundException(clientIdentifierId);
|
||||
}
|
||||
ClientIdentityMapper rm = new ClientIdentityMapper();
|
||||
|
||||
}
|
||||
|
||||
private static final class ClientIdentityMapper implements RowMapper<ClientIdentifierData> {
|
||||
String sql = "select " + rm.schema();
|
||||
|
||||
public ClientIdentityMapper() {
|
||||
}
|
||||
sql += " order by ci.id";
|
||||
|
||||
public String schema() {
|
||||
return "ci.id as id, ci.client_id as clientId, ci.document_type_id as documentTypeId, ci.document_key as documentKey,"
|
||||
+ " ci.description as description, cv.code_value as documentType "
|
||||
+ " from m_client_identifier ci, m_client c, m_office o, m_code_value cv"
|
||||
+ " where ci.client_id=c.id and c.office_id=o.id"
|
||||
+ " and ci.document_type_id=cv.id"
|
||||
+ " and ci.client_id = ? and o.hierarchy like ? ";
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { clientId, hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientIdentifierData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
@Override
|
||||
public ClientIdentifierData retrieveClientIdentifier(final Long clientId, final Long clientIdentifierId) {
|
||||
try {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final Long clientId = JdbcSupport.getLong(rs, "clientId");
|
||||
final Long documentTypeId = JdbcSupport.getLong(rs, "documentTypeId");
|
||||
final String documentKey = rs.getString("documentKey");
|
||||
final String description = rs.getString("description");
|
||||
final String documentTypeName = rs.getString("documentType");
|
||||
ClientIdentityMapper rm = new ClientIdentityMapper();
|
||||
|
||||
return ClientIdentifierData.singleItem(id, clientId, documentTypeId,documentKey, description,documentTypeName);
|
||||
}
|
||||
String sql = "select " + rm.schema();
|
||||
|
||||
}
|
||||
sql += " and ci.id = ?";
|
||||
|
||||
@Override
|
||||
public ClientData retrieveClientByIdentifier(
|
||||
final Long identifierTypeId,
|
||||
final String identifierKey) {
|
||||
try {
|
||||
final ClientIdentifierMapper mapper = new ClientIdentifierMapper();
|
||||
final ClientIdentifierData clientIdentifierData = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { clientId,
|
||||
hierarchySearchString, clientIdentifierId });
|
||||
|
||||
final String sql = "select " + mapper.clientLookupByIdentifierSchema();
|
||||
return clientIdentifierData;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new ClientIdentifierNotFoundException(clientIdentifierId);
|
||||
}
|
||||
|
||||
return jdbcTemplate.queryForObject(sql, mapper, new Object[] { identifierTypeId, identifierKey });
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ClientIdentifierMapper implements RowMapper<ClientData> {
|
||||
}
|
||||
|
||||
public String clientLookupByIdentifierSchema() {
|
||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname, "
|
||||
+ "c.office_id as officeId, o.name as officeName "
|
||||
+ "from m_client c, m_office o, m_client_identifier ci "
|
||||
+ "where o.id = c.office_id and c.id=ci.client_id "
|
||||
+ "and ci.document_type_id= ? and ci.document_key like ?";
|
||||
}
|
||||
private static final class ClientIdentityMapper implements RowMapper<ClientIdentifierData> {
|
||||
|
||||
@Override
|
||||
public ClientData mapRow(final ResultSet rs,
|
||||
@SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
String firstname = rs.getString("firstname");
|
||||
if (StringUtils.isBlank(firstname)) {
|
||||
firstname = "";
|
||||
}
|
||||
final String lastname = rs.getString("lastname");
|
||||
|
||||
final Long officeId = rs.getLong("officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
return ClientData.clientIdentifier(id, firstname, lastname, officeId, officeName);
|
||||
}
|
||||
}
|
||||
public ClientIdentityMapper() {}
|
||||
|
||||
public String schema() {
|
||||
return "ci.id as id, ci.client_id as clientId, ci.document_type_id as documentTypeId, ci.document_key as documentKey,"
|
||||
+ " ci.description as description, cv.code_value as documentType "
|
||||
+ " from m_client_identifier ci, m_client c, m_office o, m_code_value cv"
|
||||
+ " where ci.client_id=c.id and c.office_id=o.id" + " and ci.document_type_id=cv.id"
|
||||
+ " and ci.client_id = ? and o.hierarchy like ? ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientIdentifierData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final Long clientId = JdbcSupport.getLong(rs, "clientId");
|
||||
final Long documentTypeId = JdbcSupport.getLong(rs, "documentTypeId");
|
||||
final String documentKey = rs.getString("documentKey");
|
||||
final String description = rs.getString("description");
|
||||
final String documentTypeName = rs.getString("documentType");
|
||||
|
||||
return ClientIdentifierData.singleItem(id, clientId, documentTypeId, documentKey, description, documentTypeName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientData retrieveClientByIdentifier(final Long identifierTypeId, final String identifierKey) {
|
||||
try {
|
||||
final ClientIdentifierMapper mapper = new ClientIdentifierMapper();
|
||||
|
||||
final String sql = "select " + mapper.clientLookupByIdentifierSchema();
|
||||
|
||||
return jdbcTemplate.queryForObject(sql, mapper, new Object[] { identifierTypeId, identifierKey });
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ClientIdentifierMapper implements RowMapper<ClientData> {
|
||||
|
||||
public String clientLookupByIdentifierSchema() {
|
||||
return "c.id as id, c.firstname as firstname, c.lastname as lastname, " + "c.office_id as officeId, o.name as officeName "
|
||||
+ "from m_client c, m_office o, m_client_identifier ci " + "where o.id = c.office_id and c.id=ci.client_id "
|
||||
+ "and ci.document_type_id= ? and ci.document_key like ?";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = rs.getLong("id");
|
||||
String firstname = rs.getString("firstname");
|
||||
if (StringUtils.isBlank(firstname)) {
|
||||
firstname = "";
|
||||
}
|
||||
final String lastname = rs.getString("lastname");
|
||||
|
||||
final Long officeId = rs.getLong("officeId");
|
||||
final String officeName = rs.getString("officeName");
|
||||
|
||||
return ClientData.clientIdentifier(id, firstname, lastname, officeId, officeName);
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,6 +2,6 @@ package org.mifosng.platform.makerchecker.service;
|
||||
|
||||
public interface ChangeDetectionService {
|
||||
|
||||
String detectChanges(String operation, String resourceName, Long resourceId, String commandSerializedAsJson);
|
||||
String detectChangesOnUpdate(String resourceName, Long resourceId, String commandSerializedAsJson);
|
||||
|
||||
}
|
||||
+17
-14
@@ -24,23 +24,26 @@ public class ChangeDetectionServiceJdbc implements ChangeDetectionService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String detectChanges(final String operation, final String resourceName, final Long resourceId,
|
||||
final String commandSerializedAsJson) {
|
||||
public String detectChangesOnUpdate(final String resourceName, final Long resourceId, final String commandSerializedAsJson) {
|
||||
|
||||
String changesOnlyJson = "";
|
||||
|
||||
// FIXME - KW/JW - this change detection code for update of clients
|
||||
// using ClientCommand can re placed when more suitable sql version is
|
||||
// implemented.
|
||||
final ClientData originalClient = this.clientReadPlatformService.retrieveIndividualClient(resourceId);
|
||||
final ClientData changedClient = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(resourceId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
final String baseJson = this.apiJsonSerializerService.serializeClientDataToJson(originalClient);
|
||||
final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient);
|
||||
final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson);
|
||||
|
||||
changesOnlyJson = this.apiJsonSerializerService.serializeClientCommandToJson(changesOnly);
|
||||
if ("clients".equalsIgnoreCase(resourceName)) {
|
||||
// FIXME - KW/JW - this change detection code for update of clients
|
||||
// using ClientCommand can re placed when more suitable sql version is
|
||||
// implemented.
|
||||
final ClientData originalClient = this.clientReadPlatformService.retrieveIndividualClient(resourceId);
|
||||
final ClientData changedClient = this.apiDataConversionService.convertInternalJsonFormatToClientDataChange(resourceId,
|
||||
commandSerializedAsJson);
|
||||
|
||||
final String baseJson = this.apiJsonSerializerService.serializeClientDataToJson(originalClient);
|
||||
final String workingJson = this.apiJsonSerializerService.serializeClientDataToJson(changedClient);
|
||||
final ClientCommand changesOnly = this.apiDataConversionService.detectChanges(resourceId, baseJson, workingJson);
|
||||
|
||||
changesOnlyJson = this.apiJsonSerializerService.serializeClientCommandToJson(changesOnly);
|
||||
} else {
|
||||
changesOnlyJson = commandSerializedAsJson;
|
||||
}
|
||||
|
||||
return changesOnlyJson;
|
||||
}
|
||||
|
||||
+1
-2
@@ -57,8 +57,7 @@ public class ClientCommandHandler implements CommandSourceHandler {
|
||||
}
|
||||
} else if (commandSource.isUpdate()) {
|
||||
try {
|
||||
final String jsonOfChangesOnly = this.changeDetectionService.detectChanges(commandSource.operation(),
|
||||
commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson);
|
||||
final String jsonOfChangesOnly = this.changeDetectionService.detectChangesOnUpdate(commandSource.resourceName(), commandSource.resourceId(), commandSerializedAsJson);
|
||||
commandSourceResult.updateJsonTo(jsonOfChangesOnly);
|
||||
|
||||
final ClientCommand changesOnly = this.apiDataConversionService.convertInternalJsonFormatToClientCommand(
|
||||
|
||||
+7
-7
@@ -9,17 +9,17 @@ import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
|
||||
public interface OfficeReadPlatformService {
|
||||
|
||||
Collection<OfficeData> retrieveAllOffices();
|
||||
Collection<OfficeData> retrieveAllOffices();
|
||||
|
||||
Collection<OfficeLookup> retrieveAllOfficesForLookup();
|
||||
Collection<OfficeLookup> retrieveAllOfficesForLookup();
|
||||
|
||||
OfficeData retrieveOffice(Long officeId);
|
||||
OfficeData retrieveOffice(Long officeId);
|
||||
|
||||
OfficeData retrieveNewOfficeTemplate();
|
||||
OfficeData retrieveNewOfficeTemplate();
|
||||
|
||||
List<OfficeLookup> retrieveAllowedParents(Long officeId);
|
||||
List<OfficeLookup> retrieveAllowedParents(Long officeId);
|
||||
|
||||
Collection<OfficeTransactionData> retrieveAllOfficeTransactions();
|
||||
Collection<OfficeTransactionData> retrieveAllOfficeTransactions();
|
||||
|
||||
OfficeTransactionData retrieveNewOfficeTransactionDetails();
|
||||
OfficeTransactionData retrieveNewOfficeTransactionDetails();
|
||||
}
|
||||
+145
-172
@@ -27,231 +27,204 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final CurrencyReadPlatformService currencyReadPlatformService;
|
||||
private final static String nameDecoratedBaseOnHierarchy = "concat(substring('........................................', 1, ((LENGTH(o.hierarchy) - LENGTH(REPLACE(o.hierarchy, '.', '')) - 1) * 4)), o.name)";
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final CurrencyReadPlatformService currencyReadPlatformService;
|
||||
private final static String nameDecoratedBaseOnHierarchy = "concat(substring('........................................', 1, ((LENGTH(o.hierarchy) - LENGTH(REPLACE(o.hierarchy, '.', '')) - 1) * 4)), o.name)";
|
||||
|
||||
@Autowired
|
||||
public OfficeReadPlatformServiceImpl(final PlatformSecurityContext context,
|
||||
final CurrencyReadPlatformService currencyReadPlatformService,
|
||||
final TenantAwareRoutingDataSource dataSource) {
|
||||
this.context = context;
|
||||
this.currencyReadPlatformService = currencyReadPlatformService;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
@Autowired
|
||||
public OfficeReadPlatformServiceImpl(final PlatformSecurityContext context,
|
||||
final CurrencyReadPlatformService currencyReadPlatformService, final TenantAwareRoutingDataSource dataSource) {
|
||||
this.context = context;
|
||||
this.currencyReadPlatformService = currencyReadPlatformService;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
private static final class OfficeMapper implements RowMapper<OfficeData> {
|
||||
private static final class OfficeMapper implements RowMapper<OfficeData> {
|
||||
|
||||
public String officeSchema() {
|
||||
return " o.id as id, o.name as name, "
|
||||
+ nameDecoratedBaseOnHierarchy
|
||||
+ " as nameDecorated, o.external_id as externalId, o.opening_date as openingDate, o.hierarchy as hierarchy, parent.id as parentId, parent.name as parentName "
|
||||
+ "from m_office o LEFT JOIN m_office AS parent ON parent.id = o.parent_id ";
|
||||
}
|
||||
public String officeSchema() {
|
||||
return " o.id as id, o.name as name, "
|
||||
+ nameDecoratedBaseOnHierarchy
|
||||
+ " as nameDecorated, o.external_id as externalId, o.opening_date as openingDate, o.hierarchy as hierarchy, parent.id as parentId, parent.name as parentName "
|
||||
+ "from m_office o LEFT JOIN m_office AS parent ON parent.id = o.parent_id ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
@Override
|
||||
public OfficeData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String nameDecorated = rs.getString("nameDecorated");
|
||||
String externalId = rs.getString("externalId");
|
||||
LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate");
|
||||
String hierarchy = rs.getString("hierarchy");
|
||||
Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
String parentName = rs.getString("parentName");
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String nameDecorated = rs.getString("nameDecorated");
|
||||
String externalId = rs.getString("externalId");
|
||||
LocalDate openingDate = JdbcSupport.getLocalDate(rs, "openingDate");
|
||||
String hierarchy = rs.getString("hierarchy");
|
||||
Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
String parentName = rs.getString("parentName");
|
||||
|
||||
List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>();
|
||||
return new OfficeData(id, name, nameDecorated, externalId,
|
||||
openingDate, hierarchy, parentId, parentName,
|
||||
allowedParents);
|
||||
}
|
||||
}
|
||||
List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>();
|
||||
return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, parentId, parentName, allowedParents);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OfficeLookupMapper implements
|
||||
RowMapper<OfficeLookup> {
|
||||
private static final class OfficeLookupMapper implements RowMapper<OfficeLookup> {
|
||||
|
||||
public String officeLookupSchema() {
|
||||
return " o.id as id, " + nameDecoratedBaseOnHierarchy
|
||||
+ " as nameDecorated, o.name as name from m_office o ";
|
||||
}
|
||||
public String officeLookupSchema() {
|
||||
return " o.id as id, " + nameDecoratedBaseOnHierarchy + " as nameDecorated, o.name as name from m_office o ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
@Override
|
||||
public OfficeLookup mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String nameDecorated = rs.getString("nameDecorated");
|
||||
Long id = rs.getLong("id");
|
||||
String name = rs.getString("name");
|
||||
String nameDecorated = rs.getString("nameDecorated");
|
||||
|
||||
return new OfficeLookup(id, name, nameDecorated);
|
||||
}
|
||||
}
|
||||
return new OfficeLookup(id, name, nameDecorated);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OfficeTransactionMapper implements
|
||||
RowMapper<OfficeTransactionData> {
|
||||
private static final class OfficeTransactionMapper implements RowMapper<OfficeTransactionData> {
|
||||
|
||||
public String officeTransactionSchema() {
|
||||
return " ot.id as id, ot.transaction_date as transactionDate, ot.from_office_id as fromOfficeId, fromoff.name as fromOfficeName, "
|
||||
+ " ot.to_office_id as toOfficeId, tooff.name as toOfficeName, ot.transaction_amount as transactionAmount, ot.description as description, "
|
||||
+ " ot.currency_code as currencyCode, rc.decimal_places as currencyDigits, "
|
||||
+ "rc.name as currencyName, rc.internationalized_name_code as currencyNameCode, rc.display_symbol as currencyDisplaySymbol "
|
||||
public String officeTransactionSchema() {
|
||||
return " ot.id as id, ot.transaction_date as transactionDate, ot.from_office_id as fromOfficeId, fromoff.name as fromOfficeName, "
|
||||
+ " ot.to_office_id as toOfficeId, tooff.name as toOfficeName, ot.transaction_amount as transactionAmount, ot.description as description, "
|
||||
+ " ot.currency_code as currencyCode, rc.decimal_places as currencyDigits, "
|
||||
+ "rc.name as currencyName, rc.internationalized_name_code as currencyNameCode, rc.display_symbol as currencyDisplaySymbol "
|
||||
|
||||
+ " from m_office_transaction ot "
|
||||
+ " left join m_office fromoff on fromoff.id = ot.from_office_id "
|
||||
+ " left join m_office tooff on tooff.id = ot.to_office_id "
|
||||
+ " join m_currency rc on rc.`code` = ot.currency_code";
|
||||
}
|
||||
+ " from m_office_transaction ot "
|
||||
+ " left join m_office fromoff on fromoff.id = ot.from_office_id "
|
||||
+ " left join m_office tooff on tooff.id = ot.to_office_id " + " join m_currency rc on rc.`code` = ot.currency_code";
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeTransactionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
@Override
|
||||
public OfficeTransactionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
Long id = rs.getLong("id");
|
||||
LocalDate transactionDate = JdbcSupport.getLocalDate(rs,
|
||||
"transactionDate");
|
||||
Long fromOfficeId = JdbcSupport.getLong(rs, "fromOfficeId");
|
||||
String fromOfficeName = rs.getString("fromOfficeName");
|
||||
Long toOfficeId = JdbcSupport.getLong(rs, "toOfficeId");
|
||||
String toOfficeName = rs.getString("toOfficeName");
|
||||
Long id = rs.getLong("id");
|
||||
LocalDate transactionDate = JdbcSupport.getLocalDate(rs, "transactionDate");
|
||||
Long fromOfficeId = JdbcSupport.getLong(rs, "fromOfficeId");
|
||||
String fromOfficeName = rs.getString("fromOfficeName");
|
||||
Long toOfficeId = JdbcSupport.getLong(rs, "toOfficeId");
|
||||
String toOfficeName = rs.getString("toOfficeName");
|
||||
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
String currencyName = rs.getString("currencyName");
|
||||
String currencyNameCode = rs.getString("currencyNameCode");
|
||||
String currencyDisplaySymbol = rs
|
||||
.getString("currencyDisplaySymbol");
|
||||
Integer currencyDigits = JdbcSupport.getInteger(rs,
|
||||
"currencyDigits");
|
||||
String currencyCode = rs.getString("currencyCode");
|
||||
String currencyName = rs.getString("currencyName");
|
||||
String currencyNameCode = rs.getString("currencyNameCode");
|
||||
String currencyDisplaySymbol = rs.getString("currencyDisplaySymbol");
|
||||
Integer currencyDigits = JdbcSupport.getInteger(rs, "currencyDigits");
|
||||
|
||||
CurrencyData currencyData = new CurrencyData(currencyCode,
|
||||
currencyName, currencyDigits, currencyDisplaySymbol,
|
||||
currencyNameCode);
|
||||
CurrencyData currencyData = new CurrencyData(currencyCode, currencyName, currencyDigits, currencyDisplaySymbol,
|
||||
currencyNameCode);
|
||||
|
||||
BigDecimal transactionAmount = rs
|
||||
.getBigDecimal("transactionAmount");
|
||||
String description = rs.getString("description");
|
||||
BigDecimal transactionAmount = rs.getBigDecimal("transactionAmount");
|
||||
String description = rs.getString("description");
|
||||
|
||||
return new OfficeTransactionData(id, transactionDate, fromOfficeId,
|
||||
fromOfficeName, toOfficeId, toOfficeName, currencyData,
|
||||
transactionAmount, description);
|
||||
}
|
||||
}
|
||||
return new OfficeTransactionData(id, transactionDate, fromOfficeId, fromOfficeName, toOfficeId, toOfficeName, currencyData,
|
||||
transactionAmount, description);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OfficeData> retrieveAllOffices() {
|
||||
@Override
|
||||
public Collection<OfficeData> retrieveAllOffices() {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
OfficeMapper rm = new OfficeMapper();
|
||||
String sql = "select " + rm.officeSchema()
|
||||
+ "where o.hierarchy like ? order by o.hierarchy";
|
||||
OfficeMapper rm = new OfficeMapper();
|
||||
String sql = "select " + rm.officeSchema() + "where o.hierarchy like ? order by o.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm,
|
||||
new Object[] { hierarchySearchString });
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OfficeLookup> retrieveAllOfficesForLookup() {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
@Override
|
||||
public Collection<OfficeLookup> retrieveAllOfficesForLookup() {
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
OfficeLookupMapper rm = new OfficeLookupMapper();
|
||||
String sql = "select " + rm.officeLookupSchema()
|
||||
+ "where o.hierarchy like ? order by o.hierarchy";
|
||||
OfficeLookupMapper rm = new OfficeLookupMapper();
|
||||
String sql = "select " + rm.officeLookupSchema() + "where o.hierarchy like ? order by o.hierarchy";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm,
|
||||
new Object[] { hierarchySearchString });
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeData retrieveOffice(final Long officeId) {
|
||||
@Override
|
||||
public OfficeData retrieveOffice(final Long officeId) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
OfficeMapper rm = new OfficeMapper();
|
||||
String sql = "select " + rm.officeSchema() + " where o.id = ?";
|
||||
OfficeMapper rm = new OfficeMapper();
|
||||
String sql = "select " + rm.officeSchema() + " where o.id = ?";
|
||||
|
||||
OfficeData selectedOffice = this.jdbcTemplate.queryForObject(sql,
|
||||
rm, new Object[] { officeId });
|
||||
OfficeData selectedOffice = this.jdbcTemplate.queryForObject(sql, rm, new Object[] { officeId });
|
||||
|
||||
return selectedOffice;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new OfficeNotFoundException(officeId);
|
||||
}
|
||||
}
|
||||
return selectedOffice;
|
||||
} catch (EmptyResultDataAccessException e) {
|
||||
throw new OfficeNotFoundException(officeId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeData retrieveNewOfficeTemplate() {
|
||||
@Override
|
||||
public OfficeData retrieveNewOfficeTemplate() {
|
||||
|
||||
context.authenticatedUser();
|
||||
context.authenticatedUser();
|
||||
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>();
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>();
|
||||
|
||||
return OfficeData.template(parentLookups, new LocalDate());
|
||||
}
|
||||
return OfficeData.template(parentLookups, new LocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OfficeLookup> retrieveAllowedParents(final Long officeId) {
|
||||
@Override
|
||||
public List<OfficeLookup> retrieveAllowedParents(final Long officeId) {
|
||||
|
||||
context.authenticatedUser();
|
||||
List<OfficeLookup> filterParentLookups = new ArrayList<OfficeLookup>();
|
||||
context.authenticatedUser();
|
||||
List<OfficeLookup> filterParentLookups = new ArrayList<OfficeLookup>();
|
||||
|
||||
if (isNotHeadOffice(officeId)) {
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(
|
||||
retrieveAllOfficesForLookup());
|
||||
if (isNotHeadOffice(officeId)) {
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup());
|
||||
|
||||
for (OfficeLookup office : parentLookups) {
|
||||
for (OfficeLookup office : parentLookups) {
|
||||
|
||||
if (!office.getId().equals(officeId)) {
|
||||
filterParentLookups.add(office);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!office.hasIdentifyOf(officeId)) {
|
||||
filterParentLookups.add(office);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return filterParentLookups;
|
||||
return filterParentLookups;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isNotHeadOffice(final Long officeId) {
|
||||
return !Long.valueOf(1).equals(officeId);
|
||||
}
|
||||
private boolean isNotHeadOffice(final Long officeId) {
|
||||
return !Long.valueOf(1).equals(officeId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<OfficeTransactionData> retrieveAllOfficeTransactions() {
|
||||
@Override
|
||||
public Collection<OfficeTransactionData> retrieveAllOfficeTransactions() {
|
||||
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
AppUser currentUser = context.authenticatedUser();
|
||||
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
String hierarchy = currentUser.getOffice().getHierarchy();
|
||||
String hierarchySearchString = hierarchy + "%";
|
||||
|
||||
OfficeTransactionMapper rm = new OfficeTransactionMapper();
|
||||
String sql = "select "
|
||||
+ rm.officeTransactionSchema()
|
||||
+ " where (fromoff.hierarchy like ? or tooff.hierarchy like ?) order by ot.transaction_date, ot.id";
|
||||
OfficeTransactionMapper rm = new OfficeTransactionMapper();
|
||||
String sql = "select " + rm.officeTransactionSchema()
|
||||
+ " where (fromoff.hierarchy like ? or tooff.hierarchy like ?) order by ot.transaction_date, ot.id";
|
||||
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] {
|
||||
hierarchySearchString, hierarchySearchString });
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, rm, new Object[] { hierarchySearchString, hierarchySearchString });
|
||||
}
|
||||
|
||||
@Override
|
||||
public OfficeTransactionData retrieveNewOfficeTransactionDetails() {
|
||||
context.authenticatedUser();
|
||||
@Override
|
||||
public OfficeTransactionData retrieveNewOfficeTransactionDetails() {
|
||||
context.authenticatedUser();
|
||||
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(
|
||||
retrieveAllOfficesForLookup());
|
||||
List<CurrencyData> currencyOptions = currencyReadPlatformService
|
||||
.retrieveAllowedCurrencies();
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup());
|
||||
List<CurrencyData> currencyOptions = currencyReadPlatformService.retrieveAllowedCurrencies();
|
||||
|
||||
return new OfficeTransactionData(new LocalDate(), parentLookups,
|
||||
currencyOptions);
|
||||
}
|
||||
return new OfficeTransactionData(new LocalDate(), parentLookups, currencyOptions);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-3
@@ -4,6 +4,5 @@ import org.mifosng.platform.user.domain.AppUser;
|
||||
|
||||
public interface PlatformSecurityContext {
|
||||
|
||||
AppUser authenticatedUser();
|
||||
|
||||
}
|
||||
AppUser authenticatedUser();
|
||||
}
|
||||
+15
-16
@@ -8,26 +8,25 @@ import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* Wrapper around spring security's {@link SecurityContext} for extracted the current authenticated {@link AppUser}.
|
||||
* Wrapper around spring security's {@link SecurityContext} for extracted the
|
||||
* current authenticated {@link AppUser}.
|
||||
*/
|
||||
@Service
|
||||
public class SpringSecurityPlatformSecurityContext implements PlatformSecurityContext {
|
||||
|
||||
@Override
|
||||
public AppUser authenticatedUser() {
|
||||
AppUser currentUser = null;
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
if (context != null) {
|
||||
Authentication auth = context.getAuthentication();
|
||||
if (auth != null) {
|
||||
currentUser = (AppUser) auth.getPrincipal();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public AppUser authenticatedUser() {
|
||||
AppUser currentUser = null;
|
||||
SecurityContext context = SecurityContextHolder.getContext();
|
||||
if (context != null) {
|
||||
Authentication auth = context.getAuthentication();
|
||||
if (auth != null) {
|
||||
currentUser = (AppUser) auth.getPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
if (currentUser == null) {
|
||||
throw new UnAuthenticatedUserException();
|
||||
}
|
||||
if (currentUser == null) { throw new UnAuthenticatedUserException(); }
|
||||
|
||||
return currentUser;
|
||||
}
|
||||
return currentUser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,377 +27,351 @@ import org.springframework.security.core.userdetails.User;
|
||||
|
||||
@Entity
|
||||
@Table(name = "m_appuser", uniqueConstraints = @UniqueConstraint(columnNames = { "username" }, name = "username_org"))
|
||||
public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements
|
||||
PlatformUser {
|
||||
|
||||
@Column(name = "email", nullable = false, length = 100)
|
||||
private String email;
|
||||
|
||||
@Column(name = "username", nullable = false, length = 100)
|
||||
private String username;
|
||||
|
||||
@Column(name = "firstname", nullable = false, length = 100)
|
||||
private String firstname;
|
||||
|
||||
@Column(name = "lastname", nullable = false, length = 100)
|
||||
private String lastname;
|
||||
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
@Column(name = "nonexpired", nullable = false)
|
||||
private boolean accountNonExpired;
|
||||
|
||||
@Column(name = "nonlocked", nullable = false)
|
||||
private final boolean accountNonLocked;
|
||||
|
||||
@Column(name = "nonexpired_credentials", nullable = false)
|
||||
private final boolean credentialsNonExpired;
|
||||
|
||||
@Column(name = "enabled", nullable = false)
|
||||
private boolean enabled;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "firsttime_login_remaining", nullable = false)
|
||||
private boolean firstTimeLoginRemaining;
|
||||
|
||||
@Column(name = "is_deleted", nullable = false)
|
||||
private boolean deleted;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "office_id")
|
||||
private Office office;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "m_appuser_role", joinColumns = @JoinColumn(name = "appuser_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
|
||||
private Set<Role> roles;
|
||||
|
||||
public static AppUser createNew(final Office office,
|
||||
final Set<Role> allRoles, final String username,
|
||||
final String email, final String firstname, final String lastname,
|
||||
final String password) {
|
||||
|
||||
boolean userEnabled = true;
|
||||
boolean userAccountNonExpired = true;
|
||||
boolean userCredentialsNonExpired = true;
|
||||
boolean userAccountNonLocked = true;
|
||||
|
||||
Collection<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
|
||||
authorities.add(new SimpleGrantedAuthority(
|
||||
"DUMMY_ROLE_NOT_USED_OR_PERSISTED_TO_AVOID_EXCEPTION"));
|
||||
|
||||
User user = new User(username, password, userEnabled,
|
||||
userAccountNonExpired, userCredentialsNonExpired,
|
||||
userAccountNonLocked, authorities);
|
||||
return new AppUser(office, user, allRoles, email, firstname, lastname);
|
||||
}
|
||||
|
||||
protected AppUser() {
|
||||
this.office = null;
|
||||
this.email = null;
|
||||
this.username = null;
|
||||
this.password = null;
|
||||
this.accountNonExpired = false;
|
||||
this.accountNonLocked = false;
|
||||
this.credentialsNonExpired = false;
|
||||
this.enabled = false;
|
||||
this.roles = new HashSet<Role>();
|
||||
this.firstTimeLoginRemaining = true;
|
||||
}
|
||||
|
||||
public AppUser(final Office office, final User user, final Set<Role> roles,
|
||||
final String email, final String firstname, final String lastname) {
|
||||
this.office = office;
|
||||
this.email = email.trim();
|
||||
this.username = user.getUsername().trim();
|
||||
this.firstname = firstname.trim();
|
||||
this.lastname = lastname.trim();
|
||||
this.password = user.getPassword().trim();
|
||||
this.accountNonExpired = user.isAccountNonExpired();
|
||||
this.accountNonLocked = user.isAccountNonLocked();
|
||||
this.credentialsNonExpired = user.isCredentialsNonExpired();
|
||||
this.enabled = user.isEnabled();
|
||||
this.roles = roles;
|
||||
this.firstTimeLoginRemaining = true;
|
||||
}
|
||||
|
||||
public void updatePassword(final String encodePassword) {
|
||||
this.password = encodePassword;
|
||||
this.firstTimeLoginRemaining = false;
|
||||
}
|
||||
|
||||
public void update(final Set<Role> allRoles, final Office office,
|
||||
final UserCommand userCommand) {
|
||||
|
||||
if (userCommand.isRolesChanged() && !allRoles.isEmpty()) {
|
||||
this.roles.clear();
|
||||
this.roles = allRoles;
|
||||
}
|
||||
if (userCommand.isOfficeChanged()) {
|
||||
this.office = office;
|
||||
}
|
||||
if (userCommand.isUsernameChanged()) {
|
||||
this.username = userCommand.getUsername();
|
||||
}
|
||||
if (userCommand.isFirstnameChanged()) {
|
||||
this.firstname = userCommand.getFirstname();
|
||||
}
|
||||
if (userCommand.isLastnameChanged()) {
|
||||
this.lastname = userCommand.getLastname();
|
||||
}
|
||||
if (userCommand.isEmailChanged()) {
|
||||
this.email = userCommand.getEmail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete is a <i>soft delete</i>. Updates flag so it wont appear in
|
||||
* query/report results.
|
||||
*
|
||||
* Any fields with unique constraints and prepended with id of record.
|
||||
*/
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
this.enabled = false;
|
||||
this.accountNonExpired = false;
|
||||
this.firstTimeLoginRemaining = true;
|
||||
this.username = this.getId() + "_DELETED_" + this.username;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<GrantedAuthority> getAuthorities() {
|
||||
return this.populateGrantedAuthorities();
|
||||
}
|
||||
|
||||
private List<GrantedAuthority> populateGrantedAuthorities() {
|
||||
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
|
||||
for (Role role : this.roles) {
|
||||
Collection<Permission> permissions = role.getPermissions();
|
||||
for (Permission permission : permissions) {
|
||||
grantedAuthorities.add(new SimpleGrantedAuthority(permission
|
||||
.code()));
|
||||
}
|
||||
}
|
||||
return grantedAuthorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return this.accountNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return this.accountNonLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return this.credentialsNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public Set<Role> getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public Office getOffice() {
|
||||
return this.office;
|
||||
}
|
||||
|
||||
public boolean canNotApproveLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "APPROVEINPAST_LOAN",
|
||||
"PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotRejectLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "REJECTINPAST_LOAN",
|
||||
"PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotWithdrawByClientLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "WITHDRAWINPAST_LOAN",
|
||||
"PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotDisburseLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "DISBURSEINPAST_LOAN",
|
||||
"PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotMakeRepaymentOnLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS",
|
||||
"REPAYMENTINPAST_LOAN", "PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForReport(String reportName) {
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "REPORTING_SUPER_USER",
|
||||
"READ_" + reportName))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForDatatable(String datatable,
|
||||
String accessType) {
|
||||
|
||||
String matchPermission = accessType + "_" + datatable;
|
||||
|
||||
if (accessType.equalsIgnoreCase("READ")) {
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ",
|
||||
matchPermission))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", matchPermission))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForSet(String type, String set,
|
||||
String accessType) {
|
||||
|
||||
String matchPermission = "CAN_" + accessType + "_" + type + "_x" + set;
|
||||
|
||||
if (accessType.equalsIgnoreCase("READ")) {
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ",
|
||||
matchPermission))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", matchPermission))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForAnyOf(final String... permissionCodes) {
|
||||
boolean hasNotPermission = true;
|
||||
for (String permissionCode : permissionCodes) {
|
||||
boolean checkPermission = this.hasPermissionTo(permissionCode);
|
||||
if (checkPermission) {
|
||||
hasNotPermission = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasNotPermission;
|
||||
}
|
||||
|
||||
public void validateHasReadPermission(final String entityType) {
|
||||
|
||||
String authorizationMessage = "User has no authority to view "
|
||||
+ entityType.toLowerCase() + "s";
|
||||
String matchPermission = "READ_" + entityType.toUpperCase();
|
||||
|
||||
if (!(hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ",
|
||||
matchPermission)))
|
||||
return;
|
||||
|
||||
String higherPermission = "";
|
||||
if (entityType.equalsIgnoreCase("CHARGE")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENT")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENTNOTE")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENTIDENTIFIER")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENTIMAGE")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CODE")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CURRENCY")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("DOCUMENTMAN")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("FUND")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("GROUP")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("LOANPRODUCT")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("LOAN")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("OFFICE")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("OFFICETRANSACTION")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("PERMISSION")) {
|
||||
higherPermission = "USER_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("ROLE")) {
|
||||
higherPermission = "USER_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("USER")) {
|
||||
higherPermission = "USER_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("STAFF")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("SAVINGSPRODUCT")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("DEPOSITPRODUCT")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("DEPOSITACCOUNT")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("SAVINGSACCOUNT")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
}
|
||||
|
||||
if (!(higherPermission.equals(""))) {
|
||||
if (hasNotPermissionForAnyOf(higherPermission))
|
||||
throw new NoAuthorizationException(authorizationMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean hasPermissionTo(final String permissionCode) {
|
||||
boolean match = false;
|
||||
for (Role role : this.roles) {
|
||||
if (role.hasPermissionTo(permissionCode)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
public boolean hasIdOf(final Long userId) {
|
||||
return getId().equals(userId);
|
||||
}
|
||||
public class AppUser extends AbstractAuditableCustom<AppUser, Long> implements PlatformUser {
|
||||
|
||||
@Column(name = "email", nullable = false, length = 100)
|
||||
private String email;
|
||||
|
||||
@Column(name = "username", nullable = false, length = 100)
|
||||
private String username;
|
||||
|
||||
@Column(name = "firstname", nullable = false, length = 100)
|
||||
private String firstname;
|
||||
|
||||
@Column(name = "lastname", nullable = false, length = 100)
|
||||
private String lastname;
|
||||
|
||||
@Column(name = "password", nullable = false)
|
||||
private String password;
|
||||
|
||||
@Column(name = "nonexpired", nullable = false)
|
||||
private boolean accountNonExpired;
|
||||
|
||||
@Column(name = "nonlocked", nullable = false)
|
||||
private final boolean accountNonLocked;
|
||||
|
||||
@Column(name = "nonexpired_credentials", nullable = false)
|
||||
private final boolean credentialsNonExpired;
|
||||
|
||||
@Column(name = "enabled", nullable = false)
|
||||
private boolean enabled;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
@Column(name = "firsttime_login_remaining", nullable = false)
|
||||
private boolean firstTimeLoginRemaining;
|
||||
|
||||
@Column(name = "is_deleted", nullable = false)
|
||||
private boolean deleted;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "office_id")
|
||||
private Office office;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "m_appuser_role", joinColumns = @JoinColumn(name = "appuser_id"), inverseJoinColumns = @JoinColumn(name = "role_id"))
|
||||
private Set<Role> roles;
|
||||
|
||||
public static AppUser createNew(final Office office, final Set<Role> allRoles, final String username, final String email,
|
||||
final String firstname, final String lastname, final String password) {
|
||||
|
||||
boolean userEnabled = true;
|
||||
boolean userAccountNonExpired = true;
|
||||
boolean userCredentialsNonExpired = true;
|
||||
boolean userAccountNonLocked = true;
|
||||
|
||||
Collection<SimpleGrantedAuthority> authorities = new ArrayList<SimpleGrantedAuthority>();
|
||||
authorities.add(new SimpleGrantedAuthority("DUMMY_ROLE_NOT_USED_OR_PERSISTED_TO_AVOID_EXCEPTION"));
|
||||
|
||||
User user = new User(username, password, userEnabled, userAccountNonExpired, userCredentialsNonExpired, userAccountNonLocked,
|
||||
authorities);
|
||||
return new AppUser(office, user, allRoles, email, firstname, lastname);
|
||||
}
|
||||
|
||||
protected AppUser() {
|
||||
this.office = null;
|
||||
this.email = null;
|
||||
this.username = null;
|
||||
this.password = null;
|
||||
this.accountNonExpired = false;
|
||||
this.accountNonLocked = false;
|
||||
this.credentialsNonExpired = false;
|
||||
this.enabled = false;
|
||||
this.roles = new HashSet<Role>();
|
||||
this.firstTimeLoginRemaining = true;
|
||||
}
|
||||
|
||||
public AppUser(final Office office, final User user, final Set<Role> roles, final String email, final String firstname,
|
||||
final String lastname) {
|
||||
this.office = office;
|
||||
this.email = email.trim();
|
||||
this.username = user.getUsername().trim();
|
||||
this.firstname = firstname.trim();
|
||||
this.lastname = lastname.trim();
|
||||
this.password = user.getPassword().trim();
|
||||
this.accountNonExpired = user.isAccountNonExpired();
|
||||
this.accountNonLocked = user.isAccountNonLocked();
|
||||
this.credentialsNonExpired = user.isCredentialsNonExpired();
|
||||
this.enabled = user.isEnabled();
|
||||
this.roles = roles;
|
||||
this.firstTimeLoginRemaining = true;
|
||||
}
|
||||
|
||||
public void updatePassword(final String encodePassword) {
|
||||
this.password = encodePassword;
|
||||
this.firstTimeLoginRemaining = false;
|
||||
}
|
||||
|
||||
public void update(final Set<Role> allRoles, final Office office, final UserCommand userCommand) {
|
||||
|
||||
if (userCommand.isRolesChanged() && !allRoles.isEmpty()) {
|
||||
this.roles.clear();
|
||||
this.roles = allRoles;
|
||||
}
|
||||
if (userCommand.isOfficeChanged()) {
|
||||
this.office = office;
|
||||
}
|
||||
if (userCommand.isUsernameChanged()) {
|
||||
this.username = userCommand.getUsername();
|
||||
}
|
||||
if (userCommand.isFirstnameChanged()) {
|
||||
this.firstname = userCommand.getFirstname();
|
||||
}
|
||||
if (userCommand.isLastnameChanged()) {
|
||||
this.lastname = userCommand.getLastname();
|
||||
}
|
||||
if (userCommand.isEmailChanged()) {
|
||||
this.email = userCommand.getEmail();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete is a <i>soft delete</i>. Updates flag so it wont appear in
|
||||
* query/report results.
|
||||
*
|
||||
* Any fields with unique constraints and prepended with id of record.
|
||||
*/
|
||||
public void delete() {
|
||||
this.deleted = true;
|
||||
this.enabled = false;
|
||||
this.accountNonExpired = false;
|
||||
this.firstTimeLoginRemaining = true;
|
||||
this.username = this.getId() + "_DELETED_" + this.username;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<GrantedAuthority> getAuthorities() {
|
||||
return this.populateGrantedAuthorities();
|
||||
}
|
||||
|
||||
private List<GrantedAuthority> populateGrantedAuthorities() {
|
||||
List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>();
|
||||
for (Role role : this.roles) {
|
||||
Collection<Permission> permissions = role.getPermissions();
|
||||
for (Permission permission : permissions) {
|
||||
grantedAuthorities.add(new SimpleGrantedAuthority(permission.code()));
|
||||
}
|
||||
}
|
||||
return grantedAuthorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPassword() {
|
||||
return this.password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonExpired() {
|
||||
return this.accountNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAccountNonLocked() {
|
||||
return this.accountNonLocked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return this.credentialsNonExpired;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
}
|
||||
|
||||
public Set<Role> getRoles() {
|
||||
return this.roles;
|
||||
}
|
||||
|
||||
public Office getOffice() {
|
||||
return this.office;
|
||||
}
|
||||
|
||||
public boolean canNotApproveLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "APPROVEINPAST_LOAN", "PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotRejectLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "REJECTINPAST_LOAN", "PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotWithdrawByClientLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "WITHDRAWINPAST_LOAN", "PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotDisburseLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "DISBURSEINPAST_LOAN", "PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean canNotMakeRepaymentOnLoanInPast() {
|
||||
return hasNotPermissionForAnyOf("ALL_FUNCTIONS", "REPAYMENTINPAST_LOAN", "PORTFOLIO_MANAGEMENT_SUPER_USER");
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForReport(String reportName) {
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", "REPORTING_SUPER_USER", "READ_" + reportName)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForDatatable(String datatable, String accessType) {
|
||||
|
||||
String matchPermission = accessType + "_" + datatable;
|
||||
|
||||
if (accessType.equalsIgnoreCase("READ")) {
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", matchPermission)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForSet(String type, String set, String accessType) {
|
||||
|
||||
String matchPermission = "CAN_" + accessType + "_" + type + "_x" + set;
|
||||
|
||||
if (accessType.equalsIgnoreCase("READ")) {
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (hasNotPermissionForAnyOf("ALL_FUNCTIONS", matchPermission)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasNotPermissionForAnyOf(final String... permissionCodes) {
|
||||
boolean hasNotPermission = true;
|
||||
for (String permissionCode : permissionCodes) {
|
||||
boolean checkPermission = this.hasPermissionTo(permissionCode);
|
||||
if (checkPermission) {
|
||||
hasNotPermission = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return hasNotPermission;
|
||||
}
|
||||
|
||||
public void validateHasReadPermission(final String entityType) {
|
||||
|
||||
String authorizationMessage = "User has no authority to view " + entityType.toLowerCase() + "s";
|
||||
String matchPermission = "READ_" + entityType.toUpperCase();
|
||||
|
||||
if (!(hasNotPermissionForAnyOf("ALL_FUNCTIONS", "ALL_FUNCTIONS_READ", matchPermission))) return;
|
||||
|
||||
String higherPermission = "";
|
||||
if (entityType.equalsIgnoreCase("CHARGE")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENT")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENTNOTE")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENTIDENTIFIER")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CLIENTIMAGE")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CODE")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("CURRENCY")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("DOCUMENTMAN")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("FUND")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("GROUP")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("LOANPRODUCT")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("LOAN")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("OFFICE")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("OFFICETRANSACTION")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("PERMISSION")) {
|
||||
higherPermission = "USER_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("ROLE")) {
|
||||
higherPermission = "USER_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("USER")) {
|
||||
higherPermission = "USER_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("STAFF")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("SAVINGSPRODUCT")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("DEPOSITPRODUCT")) {
|
||||
higherPermission = "ORGANISATION_ADMINISTRATION_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("DEPOSITACCOUNT")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
} else if (entityType.equalsIgnoreCase("SAVINGSACCOUNT")) {
|
||||
higherPermission = "PORTFOLIO_MANAGEMENT_SUPER_USER";
|
||||
}
|
||||
|
||||
if (!(higherPermission.equals(""))) {
|
||||
if (hasNotPermissionForAnyOf(higherPermission)) throw new NoAuthorizationException(authorizationMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean hasPermissionTo(final String permissionCode) {
|
||||
boolean match = false;
|
||||
for (Role role : this.roles) {
|
||||
if (role.hasPermissionTo(permissionCode)) {
|
||||
match = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return match;
|
||||
}
|
||||
|
||||
public boolean hasIdOf(final Long userId) {
|
||||
return getId().equals(userId);
|
||||
}
|
||||
}
|
||||
@@ -22,11 +22,11 @@ import org.mifosng.platform.infrastructure.AbstractAuditableCustom;
|
||||
@Table(name = "m_role")
|
||||
public class Role extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
@Column(name="name", nullable=false, length=100)
|
||||
private String name;
|
||||
@Column(name = "name", nullable = false, length = 100)
|
||||
private String name;
|
||||
|
||||
@Column(name="description", nullable=false, length=500)
|
||||
private String description;
|
||||
@Column(name = "description", nullable = false, length = 500)
|
||||
private String description;
|
||||
|
||||
@ManyToMany(fetch = FetchType.EAGER)
|
||||
@JoinTable(name = "m_role_permission", joinColumns = @JoinColumn(name = "role_id"), inverseJoinColumns = @JoinColumn(name = "permission_id"))
|
||||
@@ -58,30 +58,30 @@ public class Role extends AbstractAuditableCustom<AppUser, Long> {
|
||||
return match;
|
||||
}
|
||||
|
||||
public RoleData toData() {
|
||||
|
||||
Collection<PermissionData> rolePermissions = new ArrayList<PermissionData>();
|
||||
for (Permission permission : this.permissions) {
|
||||
PermissionData permissionData = permission.toData();
|
||||
rolePermissions.add(permissionData);
|
||||
}
|
||||
|
||||
return new RoleData(this.getId(), this.name, this.description, rolePermissions);
|
||||
}
|
||||
public RoleData toData() {
|
||||
|
||||
public void update(final RoleCommand command) {
|
||||
if (command.isNameChanged()) {
|
||||
this.name = command.getName();
|
||||
}
|
||||
|
||||
if (command.isDescriptionChanged()) {
|
||||
this.description = command.getDescription();
|
||||
}
|
||||
|
||||
}
|
||||
Collection<PermissionData> rolePermissions = new ArrayList<PermissionData>();
|
||||
for (Permission permission : this.permissions) {
|
||||
PermissionData permissionData = permission.toData();
|
||||
rolePermissions.add(permissionData);
|
||||
}
|
||||
|
||||
return new RoleData(this.getId(), this.name, this.description, rolePermissions);
|
||||
}
|
||||
|
||||
public void update(final RoleCommand command) {
|
||||
if (command.isNameChanged()) {
|
||||
this.name = command.getName();
|
||||
}
|
||||
|
||||
if (command.isDescriptionChanged()) {
|
||||
this.description = command.getDescription();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
+3
-3
@@ -6,9 +6,9 @@ import org.mifosng.platform.api.data.AppUserData;
|
||||
|
||||
public interface AppUserReadPlatformService {
|
||||
|
||||
Collection<AppUserData> retrieveAllUsers();
|
||||
Collection<AppUserData> retrieveAllUsers();
|
||||
|
||||
AppUserData retrieveNewUserDetails();
|
||||
AppUserData retrieveNewUserDetails();
|
||||
|
||||
AppUserData retrieveUser(Long userId);
|
||||
AppUserData retrieveUser(Long userId);
|
||||
}
|
||||
+6
-5
@@ -6,14 +6,15 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
public interface AppUserWritePlatformService {
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'USER_ADMINISTRATION_SUPER_USER', 'CREATE_USER')")
|
||||
Long createUser(final UserCommand command);
|
||||
Long createUser(final UserCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'USER_ADMINISTRATION_SUPER_USER', 'UPDATE_USER')")
|
||||
Long updateUser(final UserCommand command);
|
||||
Long updateUser(final UserCommand command);
|
||||
|
||||
@PreAuthorize(value = "hasAnyRole('ALL_FUNCTIONS', 'USER_ADMINISTRATION_SUPER_USER', 'DELETE_USER')")
|
||||
void deleteUser(final Long userId);
|
||||
void deleteUser(final Long userId);
|
||||
|
||||
// we dont put any permissions on this e.g. a user with no admin rights can change their own details (email, username, password etc).
|
||||
void updateUsersOwnAccountDetails(UserCommand command);
|
||||
// we dont put any permissions on this e.g. a user with no admin rights can
|
||||
// change their own details (email, username, password etc).
|
||||
void updateUsersOwnAccountDetails(UserCommand command);
|
||||
}
|
||||
+147
-154
@@ -36,164 +36,157 @@ import org.springframework.util.ObjectUtils;
|
||||
@Service
|
||||
public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWritePlatformService {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(AppUserWritePlatformServiceJpaRepositoryImpl.class);
|
||||
|
||||
private final PlatformSecurityContext context;
|
||||
private final UserDomainService userDomainService;
|
||||
private final PlatformPasswordEncoder platformPasswordEncoder;
|
||||
private final AppUserRepository appUserRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository, final UserDomainService userDomainService,
|
||||
final OfficeRepository officeRepository, final RoleRepository roleRepository, final PlatformPasswordEncoder platformPasswordEncoder) {
|
||||
this.context = context;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.userDomainService = userDomainService;
|
||||
this.officeRepository = officeRepository;
|
||||
this.roleRepository = roleRepository;
|
||||
this.platformPasswordEncoder = platformPasswordEncoder;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long createUser(final UserCommand command) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
UserCommandValidator validator = new UserCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
|
||||
final Set<Role> allRoles = assembleSetOfRoles(command);
|
||||
private final static Logger logger = LoggerFactory.getLogger(AppUserWritePlatformServiceJpaRepositoryImpl.class);
|
||||
|
||||
Office office = this.officeRepository.findOne(command.getOfficeId());
|
||||
if (office == null) {
|
||||
throw new OfficeNotFoundException(command.getOfficeId());
|
||||
}
|
||||
private final PlatformSecurityContext context;
|
||||
private final UserDomainService userDomainService;
|
||||
private final PlatformPasswordEncoder platformPasswordEncoder;
|
||||
private final AppUserRepository appUserRepository;
|
||||
private final OfficeRepository officeRepository;
|
||||
private final RoleRepository roleRepository;
|
||||
|
||||
String password = command.getPassword();
|
||||
if (StringUtils.isBlank(password)) {
|
||||
password = "autogenerate";
|
||||
}
|
||||
|
||||
AppUser appUser = AppUser.createNew(office,
|
||||
allRoles, command.getUsername(), command.getEmail(),
|
||||
command.getFirstname(), command.getLastname(),
|
||||
password);
|
||||
|
||||
this.userDomainService.create(appUser);
|
||||
|
||||
return appUser.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return Long.valueOf(-1);
|
||||
} catch (PlatformEmailSendException e) {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
ApiParameterError error = ApiParameterError.parameterError("error.msg.user.email.invalid", "The parameter email is invalid.", "email", command.getEmail());
|
||||
dataValidationErrors.add(error);
|
||||
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
|
||||
}
|
||||
}
|
||||
@Autowired
|
||||
public AppUserWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final AppUserRepository appUserRepository,
|
||||
final UserDomainService userDomainService, final OfficeRepository officeRepository, final RoleRepository roleRepository,
|
||||
final PlatformPasswordEncoder platformPasswordEncoder) {
|
||||
this.context = context;
|
||||
this.appUserRepository = appUserRepository;
|
||||
this.userDomainService = userDomainService;
|
||||
this.officeRepository = officeRepository;
|
||||
this.roleRepository = roleRepository;
|
||||
this.platformPasswordEncoder = platformPasswordEncoder;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long updateUser(final UserCommand command) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
UserCommandValidator validator = new UserCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
|
||||
final Set<Role> allRoles = assembleSetOfRoles(command);
|
||||
@Transactional
|
||||
@Override
|
||||
public Long createUser(final UserCommand command) {
|
||||
|
||||
Office office = null;
|
||||
if (command.isOfficeChanged()) {
|
||||
office = this.officeRepository.findOne(command.getOfficeId());
|
||||
if (office == null) {
|
||||
throw new OfficeNotFoundException(command.getOfficeId());
|
||||
}
|
||||
}
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
AppUser userToUpdate = this.appUserRepository.findOne(command.getId());
|
||||
if (userToUpdate == null) {
|
||||
throw new UserNotFoundException(command.getId());
|
||||
}
|
||||
|
||||
userToUpdate.update(allRoles, office, command);
|
||||
this.appUserRepository.saveAndFlush(userToUpdate);
|
||||
|
||||
if (command.isPasswordChanged()) {
|
||||
PlatformUser dummyPlatformUser = new BasicPasswordEncodablePlatformUser(
|
||||
userToUpdate.getId(),
|
||||
userToUpdate.getUsername(), command.getPassword());
|
||||
UserCommandValidator validator = new UserCommandValidator(command);
|
||||
validator.validateForCreate();
|
||||
|
||||
String newPasswordEncoded = this.platformPasswordEncoder.encode(dummyPlatformUser);
|
||||
|
||||
userToUpdate.updatePassword(newPasswordEncoded);
|
||||
this.appUserRepository.saveAndFlush(userToUpdate);
|
||||
}
|
||||
|
||||
return userToUpdate.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updateUsersOwnAccountDetails(final UserCommand command) {
|
||||
updateUser(command);
|
||||
}
|
||||
|
||||
private Set<Role> assembleSetOfRoles(final UserCommand command) {
|
||||
|
||||
final Set<Role> allRoles = new HashSet<Role>();
|
||||
|
||||
String[] rolesArray = command.getRoles();
|
||||
if (command.isRolesChanged() && !ObjectUtils.isEmpty(rolesArray)) {
|
||||
for (String roleId : rolesArray) {
|
||||
Long id = Long.valueOf(roleId);
|
||||
Role role = this.roleRepository.findOne(id);
|
||||
if (role == null) {
|
||||
throw new RoleNotFoundException(id);
|
||||
}
|
||||
allRoles.add(role);
|
||||
}
|
||||
}
|
||||
|
||||
return allRoles;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteUser(final Long userId) {
|
||||
|
||||
AppUser user = this.appUserRepository.findOne(userId);
|
||||
if (user == null || user.isDeleted()) {
|
||||
throw new UserNotFoundException(userId);
|
||||
}
|
||||
|
||||
user.delete();
|
||||
this.appUserRepository.save(user);
|
||||
}
|
||||
|
||||
/*
|
||||
* Guaranteed to throw an exception no matter what the data integrity issue is.
|
||||
*/
|
||||
private void handleDataIntegrityIssues(final UserCommand command, final DataIntegrityViolationException dve) {
|
||||
|
||||
Throwable realCause = dve.getMostSpecificCause();
|
||||
if (realCause.getMessage().contains("username_org")) {
|
||||
StringBuilder defaultMessageBuilder = new StringBuilder("User with username ").append(command.getUsername()).append(" already exists.");
|
||||
throw new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessageBuilder.toString(), "username", command.getUsername());
|
||||
}
|
||||
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
|
||||
}
|
||||
final Set<Role> allRoles = assembleSetOfRoles(command);
|
||||
|
||||
Office office = this.officeRepository.findOne(command.getOfficeId());
|
||||
if (office == null) { throw new OfficeNotFoundException(command.getOfficeId()); }
|
||||
|
||||
String password = command.getPassword();
|
||||
if (StringUtils.isBlank(password)) {
|
||||
password = "autogenerate";
|
||||
}
|
||||
|
||||
AppUser appUser = AppUser.createNew(office, allRoles, command.getUsername(), command.getEmail(), command.getFirstname(),
|
||||
command.getLastname(), password);
|
||||
|
||||
this.userDomainService.create(appUser);
|
||||
|
||||
return appUser.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return Long.valueOf(-1);
|
||||
} catch (PlatformEmailSendException e) {
|
||||
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
|
||||
ApiParameterError error = ApiParameterError.parameterError("error.msg.user.email.invalid", "The parameter email is invalid.",
|
||||
"email", command.getEmail());
|
||||
dataValidationErrors.add(error);
|
||||
|
||||
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.",
|
||||
dataValidationErrors);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public Long updateUser(final UserCommand command) {
|
||||
|
||||
try {
|
||||
context.authenticatedUser();
|
||||
|
||||
UserCommandValidator validator = new UserCommandValidator(command);
|
||||
validator.validateForUpdate();
|
||||
|
||||
final Set<Role> allRoles = assembleSetOfRoles(command);
|
||||
|
||||
Office office = null;
|
||||
if (command.isOfficeChanged()) {
|
||||
office = this.officeRepository.findOne(command.getOfficeId());
|
||||
if (office == null) { throw new OfficeNotFoundException(command.getOfficeId()); }
|
||||
}
|
||||
|
||||
AppUser userToUpdate = this.appUserRepository.findOne(command.getId());
|
||||
if (userToUpdate == null) { throw new UserNotFoundException(command.getId()); }
|
||||
|
||||
userToUpdate.update(allRoles, office, command);
|
||||
this.appUserRepository.saveAndFlush(userToUpdate);
|
||||
|
||||
if (command.isPasswordChanged()) {
|
||||
PlatformUser dummyPlatformUser = new BasicPasswordEncodablePlatformUser(userToUpdate.getId(), userToUpdate.getUsername(),
|
||||
command.getPassword());
|
||||
|
||||
String newPasswordEncoded = this.platformPasswordEncoder.encode(dummyPlatformUser);
|
||||
|
||||
userToUpdate.updatePassword(newPasswordEncoded);
|
||||
this.appUserRepository.saveAndFlush(userToUpdate);
|
||||
}
|
||||
|
||||
return userToUpdate.getId();
|
||||
} catch (DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
return Long.valueOf(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void updateUsersOwnAccountDetails(final UserCommand command) {
|
||||
updateUser(command);
|
||||
}
|
||||
|
||||
private Set<Role> assembleSetOfRoles(final UserCommand command) {
|
||||
|
||||
final Set<Role> allRoles = new HashSet<Role>();
|
||||
|
||||
String[] rolesArray = command.getRoles();
|
||||
if (command.isRolesChanged() && !ObjectUtils.isEmpty(rolesArray)) {
|
||||
for (String roleId : rolesArray) {
|
||||
Long id = Long.valueOf(roleId);
|
||||
Role role = this.roleRepository.findOne(id);
|
||||
if (role == null) { throw new RoleNotFoundException(id); }
|
||||
allRoles.add(role);
|
||||
}
|
||||
}
|
||||
|
||||
return allRoles;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Override
|
||||
public void deleteUser(final Long userId) {
|
||||
|
||||
AppUser user = this.appUserRepository.findOne(userId);
|
||||
if (user == null || user.isDeleted()) { throw new UserNotFoundException(userId); }
|
||||
|
||||
user.delete();
|
||||
this.appUserRepository.save(user);
|
||||
}
|
||||
|
||||
/*
|
||||
* Guaranteed to throw an exception no matter what the data integrity issue
|
||||
* is.
|
||||
*/
|
||||
private void handleDataIntegrityIssues(final UserCommand command, final DataIntegrityViolationException dve) {
|
||||
|
||||
Throwable realCause = dve.getMostSpecificCause();
|
||||
if (realCause.getMessage().contains("username_org")) {
|
||||
StringBuilder defaultMessageBuilder = new StringBuilder("User with username ").append(command.getUsername()).append(
|
||||
" already exists.");
|
||||
throw new PlatformDataIntegrityException("error.msg.user.duplicate.username", defaultMessageBuilder.toString(), "username",
|
||||
command.getUsername());
|
||||
}
|
||||
|
||||
logger.error(dve.getMessage(), dve);
|
||||
throw new PlatformDataIntegrityException("error.msg.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -7,7 +7,7 @@ import org.mifosng.platform.api.data.PermissionUsageData;
|
||||
|
||||
public interface PermissionReadPlatformService {
|
||||
|
||||
Collection<PermissionData> retrieveAllPermissions();
|
||||
Collection<PermissionData> retrieveAllPermissions();
|
||||
|
||||
Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId);
|
||||
Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId);
|
||||
}
|
||||
+52
-53
@@ -17,74 +17,73 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class PermissionReadPlatformServiceImpl implements PermissionReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
|
||||
@Autowired
|
||||
public PermissionReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) {
|
||||
this.context = context;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
@Autowired
|
||||
public PermissionReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource) {
|
||||
this.context = context;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionData> retrieveAllPermissions() {
|
||||
@Override
|
||||
public Collection<PermissionData> retrieveAllPermissions() {
|
||||
|
||||
context.authenticatedUser();
|
||||
context.authenticatedUser();
|
||||
|
||||
final PermissionMapper mapper = new PermissionMapper();
|
||||
final String sql = "select " + mapper.schema() + " order by p.id";
|
||||
final PermissionMapper mapper = new PermissionMapper();
|
||||
final String sql = "select " + mapper.schema() + " order by p.id";
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||
}
|
||||
|
||||
private static final class PermissionMapper implements RowMapper<PermissionData> {
|
||||
private static final class PermissionMapper implements RowMapper<PermissionData> {
|
||||
|
||||
@Override
|
||||
public PermissionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
@Override
|
||||
public PermissionData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final String name = rs.getString("name");
|
||||
final String description = rs.getString("description");
|
||||
final String code = rs.getString("code");
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final String name = rs.getString("name");
|
||||
final String description = rs.getString("description");
|
||||
final String code = rs.getString("code");
|
||||
|
||||
return new PermissionData(id, name, description, code);
|
||||
}
|
||||
return new PermissionData(id, name, description, code);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " p.id as id, p.default_name as name, p.default_description as description, p.code as code from m_permission p ";
|
||||
}
|
||||
}
|
||||
public String schema() {
|
||||
return " p.id as id, p.default_name as name, p.default_description as description, p.code as code from m_permission p ";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<PermissionUsageData> retrieveAllRolePermissions(Long roleId) {
|
||||
|
||||
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
|
||||
final String sql = mapper.schema();
|
||||
@Override
|
||||
public Collection<PermissionUsageData> retrieveAllRolePermissions(final Long roleId) {
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {roleId});
|
||||
}
|
||||
|
||||
final PermissionUsageDataMapper mapper = new PermissionUsageDataMapper();
|
||||
final String sql = mapper.schema();
|
||||
|
||||
private static final class PermissionUsageDataMapper implements RowMapper<PermissionUsageData> {
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] { roleId });
|
||||
}
|
||||
|
||||
@Override
|
||||
public PermissionUsageData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
private static final class PermissionUsageDataMapper implements RowMapper<PermissionUsageData> {
|
||||
|
||||
final String grouping = rs.getString("grouping");
|
||||
final String code = rs.getString("code");
|
||||
final String entityName = rs.getString("entityName");
|
||||
final String actionName = rs.getString("actionName");
|
||||
final Boolean selected = rs.getBoolean("selected");
|
||||
@Override
|
||||
public PermissionUsageData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
return new PermissionUsageData(grouping, code, entityName, actionName, selected);
|
||||
}
|
||||
final String grouping = rs.getString("grouping");
|
||||
final String code = rs.getString("code");
|
||||
final String entityName = rs.getString("entityName");
|
||||
final String actionName = rs.getString("actionName");
|
||||
final Boolean selected = rs.getBoolean("selected");
|
||||
|
||||
return new PermissionUsageData(grouping, code, entityName, actionName, selected);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, if(isnull(rp.role_id), false, true) as selected "
|
||||
+ "from m_permission p "
|
||||
+ "left join m_role_permission rp on rp.permission_id = p.id and rp.role_id = ? "
|
||||
+ "order by p.grouping, ifnull(entity_name, ''), p.code";
|
||||
}
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return "select p.grouping, p.code, p.entity_name as entityName, p.action_name as actionName, if(isnull(rp.role_id), false, true) as selected " +
|
||||
"from m_permission p " +
|
||||
"left join m_role_permission rp on rp.permission_id = p.id and rp.role_id = ? " +
|
||||
"order by p.grouping, ifnull(entity_name, ''), p.code";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -6,7 +6,7 @@ import org.mifosng.platform.api.data.RoleData;
|
||||
|
||||
public interface RoleReadPlatformService {
|
||||
|
||||
Collection<RoleData> retrieveAllRoles();
|
||||
Collection<RoleData> retrieveAllRoles();
|
||||
|
||||
RoleData retrieveRole(Long roleId);
|
||||
RoleData retrieveRole(Long roleId);
|
||||
}
|
||||
+38
-39
@@ -19,53 +19,52 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final RoleRepository roleRepository;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PlatformSecurityContext context;
|
||||
private final RoleRepository roleRepository;
|
||||
|
||||
@Autowired
|
||||
public RoleReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource, final RoleRepository roleRepository) {
|
||||
this.context = context;
|
||||
this.roleRepository = roleRepository;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
@Autowired
|
||||
public RoleReadPlatformServiceImpl(final PlatformSecurityContext context, final TenantAwareRoutingDataSource dataSource,
|
||||
final RoleRepository roleRepository) {
|
||||
this.context = context;
|
||||
this.roleRepository = roleRepository;
|
||||
this.jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<RoleData> retrieveAllRoles() {
|
||||
context.authenticatedUser();
|
||||
@Override
|
||||
public Collection<RoleData> retrieveAllRoles() {
|
||||
context.authenticatedUser();
|
||||
|
||||
final RoleMapper mapper = new RoleMapper();
|
||||
final String sql = "select " + mapper.schema() + " order by r.id";
|
||||
final RoleMapper mapper = new RoleMapper();
|
||||
final String sql = "select " + mapper.schema() + " order by r.id";
|
||||
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||
}
|
||||
return this.jdbcTemplate.query(sql, mapper, new Object[] {});
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleData retrieveRole(final Long id) {
|
||||
context.authenticatedUser();
|
||||
|
||||
final Role role = this.roleRepository.findOne(id);
|
||||
if (role == null) {
|
||||
throw new RoleNotFoundException(id);
|
||||
}
|
||||
return role.toData();
|
||||
}
|
||||
@Override
|
||||
public RoleData retrieveRole(final Long id) {
|
||||
context.authenticatedUser();
|
||||
|
||||
protected static final class RoleMapper implements RowMapper<RoleData> {
|
||||
final Role role = this.roleRepository.findOne(id);
|
||||
if (role == null) { throw new RoleNotFoundException(id); }
|
||||
|
||||
return role.toData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public RoleData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum)
|
||||
throws SQLException {
|
||||
protected static final class RoleMapper implements RowMapper<RoleData> {
|
||||
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final String name = rs.getString("name");
|
||||
final String description = rs.getString("description");
|
||||
@Override
|
||||
public RoleData mapRow(final ResultSet rs, @SuppressWarnings("unused") final int rowNum) throws SQLException {
|
||||
|
||||
return new RoleData(id, name, description);
|
||||
}
|
||||
final Long id = JdbcSupport.getLong(rs, "id");
|
||||
final String name = rs.getString("name");
|
||||
final String description = rs.getString("description");
|
||||
|
||||
public String schema() {
|
||||
return " r.id as id, r.name as name, r.description as description from m_role r";
|
||||
}
|
||||
}
|
||||
return new RoleData(id, name, description);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
return " r.id as id, r.name as name, r.description as description from m_role r";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user