from MIFOX-38 - need to tidy up serialization of java objects into json across the board - this is for user admin related areas.
This commit is contained in:
@@ -12,7 +12,7 @@ import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.UriInfo;
|
||||
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||
import org.mifosng.platform.user.service.PermissionReadPlatformService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,7 +28,7 @@ public class PermissionsApiResource {
|
||||
private PermissionReadPlatformService permissionReadPlatformService;
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
private ApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@@ -40,6 +40,6 @@ public class PermissionsApiResource {
|
||||
|
||||
Collection<PermissionData> permissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
return this.apiDataConversionService.convertPermissionDataToJson(prettyPrint, responseParameters, permissions.toArray(new PermissionData[permissions.size()]));
|
||||
return this.apiJsonSerializerService.serializePermissionDataToJson(prettyPrint, responseParameters, permissions);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.mifosng.platform.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@@ -22,6 +23,7 @@ import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||
import org.mifosng.platform.user.service.PermissionReadPlatformService;
|
||||
import org.mifosng.platform.user.service.RoleReadPlatformService;
|
||||
@@ -46,6 +48,9 @@ public class RolesApiResource {
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
|
||||
@Autowired
|
||||
private ApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@@ -62,7 +67,7 @@ public class RolesApiResource {
|
||||
|
||||
Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
|
||||
|
||||
return this.apiDataConversionService.convertRoleDataToJson(prettyPrint, responseParameters, roles.toArray(new RoleData[roles.size()]));
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, roles);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -81,10 +86,9 @@ public class RolesApiResource {
|
||||
|
||||
Collection<PermissionData> allPermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
|
||||
RoleData role = new RoleData();
|
||||
role.setAvailablePermissions(allPermissions);
|
||||
RoleData role = new RoleData(allPermissions, new ArrayList<PermissionData>());
|
||||
|
||||
return this.apiDataConversionService.convertRoleDataToJson(prettyPrint, responseParameters, role);
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, role);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -119,13 +123,13 @@ public class RolesApiResource {
|
||||
if (template) {
|
||||
Collection<PermissionData> availablePermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||
availablePermissions.removeAll(role.getSelectedPermissions());
|
||||
role.setAvailablePermissions(availablePermissions);
|
||||
|
||||
role = new RoleData(role, availablePermissions);
|
||||
|
||||
responseParameters.add("availablePermissions");
|
||||
responseParameters.add("selectedPermissions");
|
||||
}
|
||||
|
||||
return this.apiDataConversionService.convertRoleDataToJson(prettyPrint, responseParameters, role);
|
||||
return this.apiJsonSerializerService.serializeRoleDataToJson(prettyPrint, responseParameters, role);
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
||||
@@ -25,6 +25,7 @@ import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.OfficeLookup;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
||||
import org.mifosng.platform.security.PlatformSecurityContext;
|
||||
@@ -52,6 +53,9 @@ public class UsersApiResource {
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
|
||||
@Autowired
|
||||
private ApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
@Autowired
|
||||
private PlatformSecurityContext context;
|
||||
|
||||
@@ -70,7 +74,7 @@ public class UsersApiResource {
|
||||
|
||||
Collection<AppUserData> users = this.appUserReadPlatformService.retrieveAllUsers();
|
||||
|
||||
return this.apiDataConversionService.convertAppUserDataToJson(prettyPrint, responseParameters, users.toArray(new AppUserData[users.size()]));
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, users);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -91,13 +95,13 @@ public class UsersApiResource {
|
||||
AppUserData user = this.appUserReadPlatformService.retrieveUser(userId);
|
||||
if (template) {
|
||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||
user.setAllowedOffices(offices);
|
||||
user = new AppUserData(user, offices);
|
||||
responseParameters.add("allowedOffices");
|
||||
responseParameters.add("availableRoles");
|
||||
responseParameters.add("selectedRoles");
|
||||
}
|
||||
|
||||
return this.apiDataConversionService.convertAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -117,7 +121,7 @@ public class UsersApiResource {
|
||||
|
||||
AppUserData user = this.appUserReadPlatformService.retrieveNewUserDetails();
|
||||
|
||||
return this.apiDataConversionService.convertAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
return this.apiJsonSerializerService.serializeAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
||||
@@ -3,112 +3,104 @@ package org.mifosng.platform.api.data;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Immutable data object for application user data.
|
||||
*/
|
||||
public class AppUserData {
|
||||
|
||||
private Long id;
|
||||
private String username;
|
||||
private Long officeId;
|
||||
private String officeName;
|
||||
private String firstname;
|
||||
private String lastname;
|
||||
private 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 List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>();
|
||||
|
||||
private List<RoleData> availableRoles = new ArrayList<RoleData>();
|
||||
private List<RoleData> selectedRoles = new ArrayList<RoleData>();
|
||||
|
||||
public AppUserData() {
|
||||
//
|
||||
}
|
||||
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 officeName, final String firstname, final String lastname, final List<RoleData> availableRoles, final List<RoleData> selectedRoles) {
|
||||
this.id = id;
|
||||
this.username = username;
|
||||
this.email = email;
|
||||
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 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>();
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return this.email;
|
||||
return username;
|
||||
}
|
||||
|
||||
public Long getOfficeId() {
|
||||
return this.officeId;
|
||||
return officeId;
|
||||
}
|
||||
|
||||
public String getOfficeName() {
|
||||
return this.officeName;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setUsername(final String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public void setEmail(final String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public void setOfficeId(final Long officeId) {
|
||||
this.officeId = officeId;
|
||||
}
|
||||
|
||||
public void setOfficeName(final String officeName) {
|
||||
this.officeName = officeName;
|
||||
}
|
||||
|
||||
public List<OfficeLookup> getAllowedOffices() {
|
||||
return allowedOffices;
|
||||
}
|
||||
|
||||
public void setAllowedOffices(List<OfficeLookup> allowedOffices) {
|
||||
this.allowedOffices = allowedOffices;
|
||||
}
|
||||
|
||||
public List<RoleData> getAvailableRoles() {
|
||||
return availableRoles;
|
||||
}
|
||||
|
||||
public void setAvailableRoles(List<RoleData> availableRoles) {
|
||||
this.availableRoles = availableRoles;
|
||||
}
|
||||
|
||||
public List<RoleData> getSelectedRoles() {
|
||||
return selectedRoles;
|
||||
}
|
||||
|
||||
public void setSelectedRoles(List<RoleData> selectedRoles) {
|
||||
this.selectedRoles = selectedRoles;
|
||||
return officeName;
|
||||
}
|
||||
|
||||
public String getFirstname() {
|
||||
return firstname;
|
||||
}
|
||||
|
||||
public void setFirstname(String firstname) {
|
||||
this.firstname = firstname;
|
||||
}
|
||||
|
||||
public String getLastname() {
|
||||
return lastname;
|
||||
}
|
||||
|
||||
public void setLastname(String lastname) {
|
||||
this.lastname = lastname;
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public List<OfficeLookup> getAllowedOffices() {
|
||||
return allowedOffices;
|
||||
}
|
||||
|
||||
public List<RoleData> getAvailableRoles() {
|
||||
return availableRoles;
|
||||
}
|
||||
|
||||
public List<RoleData> getSelectedRoles() {
|
||||
return selectedRoles;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,14 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.io.Serializable;
|
||||
/**
|
||||
* Immutable data object for permission data.
|
||||
*/
|
||||
public class PermissionData {
|
||||
|
||||
public class PermissionData implements Serializable {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String code;
|
||||
|
||||
public PermissionData() {
|
||||
//
|
||||
}
|
||||
private final Long id;
|
||||
private final String name;
|
||||
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;
|
||||
@@ -32,34 +29,18 @@ public class PermissionData implements Serializable {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public void setCode(final String code) {
|
||||
this.code = code;
|
||||
return code;
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,44 @@ package org.mifosng.platform.api.data;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Immutable data object for role data.
|
||||
*/
|
||||
public class RoleData {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String description;
|
||||
|
||||
private Collection<PermissionData> availablePermissions = new ArrayList<PermissionData>();
|
||||
private Collection<PermissionData> selectedPermissions = new ArrayList<PermissionData>();
|
||||
private final Collection<PermissionData> availablePermissions;
|
||||
private final Collection<PermissionData> selectedPermissions;
|
||||
|
||||
public RoleData() {
|
||||
//
|
||||
}
|
||||
|
||||
public RoleData(final Long id, final String name, final String description) {
|
||||
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 = new ArrayList<PermissionData>();
|
||||
this.selectedPermissions = new ArrayList<PermissionData>(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 RoleData(RoleData role, final Collection<PermissionData> availablePermissions) {
|
||||
this.id = role.getId();
|
||||
this.name = role.getName();
|
||||
this.description = role.getDescription();
|
||||
this.availablePermissions = new ArrayList<PermissionData>(availablePermissions);
|
||||
this.selectedPermissions = role.getSelectedPermissions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(final Object obj) {
|
||||
RoleData role = (RoleData) obj;
|
||||
return this.id.equals(role.getId());
|
||||
}
|
||||
@@ -34,44 +51,22 @@ public class RoleData {
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setDescription(final String description) {
|
||||
this.description = description;
|
||||
return description;
|
||||
}
|
||||
|
||||
public Collection<PermissionData> getAvailablePermissions() {
|
||||
return availablePermissions;
|
||||
}
|
||||
|
||||
public void setAvailablePermissions(
|
||||
Collection<PermissionData> availablePermissions) {
|
||||
this.availablePermissions = availablePermissions;
|
||||
}
|
||||
|
||||
public Collection<PermissionData> getSelectedPermissions() {
|
||||
return selectedPermissions;
|
||||
}
|
||||
|
||||
public void setSelectedPermissions(
|
||||
Collection<PermissionData> selectedPermissions) {
|
||||
this.selectedPermissions = selectedPermissions;
|
||||
}
|
||||
}
|
||||
+2
-11
@@ -7,8 +7,8 @@ import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.ChargeCommand;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.FundCommand;
|
||||
import org.mifosng.platform.api.commands.GroupCommand;
|
||||
import org.mifosng.platform.api.commands.LoanProductCommand;
|
||||
@@ -22,14 +22,13 @@ import org.mifosng.platform.api.commands.SavingProductCommand;
|
||||
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
||||
import org.mifosng.platform.api.commands.UserCommand;
|
||||
import org.mifosng.platform.api.data.AdditionalFieldsSetData;
|
||||
import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.AuthenticatedUserData;
|
||||
import org.mifosng.platform.api.data.ChargeData;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
|
||||
import org.mifosng.platform.api.data.ConfigurationData;
|
||||
import org.mifosng.platform.api.data.DepositProductData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
import org.mifosng.platform.api.data.DepositProductData;
|
||||
import org.mifosng.platform.api.data.FundData;
|
||||
import org.mifosng.platform.api.data.GenericResultsetData;
|
||||
import org.mifosng.platform.api.data.GroupData;
|
||||
@@ -40,19 +39,11 @@ import org.mifosng.platform.api.data.NewLoanData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.api.data.SavingProductData;
|
||||
|
||||
public interface ApiDataConversionService {
|
||||
|
||||
//
|
||||
String convertPermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, PermissionData... permissions);
|
||||
|
||||
String convertRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, RoleData... roles);
|
||||
|
||||
String convertAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, AppUserData... users);
|
||||
|
||||
String convertOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeTransactionData... officeTransactions);
|
||||
|
||||
String convertConfigurationDataToJson(boolean prettyPrint, Set<String> responseParameters, ConfigurationData... configuration);
|
||||
|
||||
+2
-109
@@ -23,8 +23,8 @@ import org.mifosng.platform.api.commands.AdjustLoanTransactionCommand;
|
||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.commands.ChargeCommand;
|
||||
import org.mifosng.platform.api.commands.ClientCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.DepositAccountCommand;
|
||||
import org.mifosng.platform.api.commands.DepositProductCommand;
|
||||
import org.mifosng.platform.api.commands.FundCommand;
|
||||
import org.mifosng.platform.api.commands.GroupCommand;
|
||||
import org.mifosng.platform.api.commands.LoanProductCommand;
|
||||
@@ -39,14 +39,13 @@ import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
||||
import org.mifosng.platform.api.commands.UserCommand;
|
||||
import org.mifosng.platform.api.data.AdditionalFieldsSetData;
|
||||
import org.mifosng.platform.api.data.ApiParameterError;
|
||||
import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.AuthenticatedUserData;
|
||||
import org.mifosng.platform.api.data.ChargeData;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
|
||||
import org.mifosng.platform.api.data.ConfigurationData;
|
||||
import org.mifosng.platform.api.data.DepositProductData;
|
||||
import org.mifosng.platform.api.data.DepositAccountData;
|
||||
import org.mifosng.platform.api.data.DepositProductData;
|
||||
import org.mifosng.platform.api.data.FundData;
|
||||
import org.mifosng.platform.api.data.GenericResultsetData;
|
||||
import org.mifosng.platform.api.data.GroupData;
|
||||
@@ -57,8 +56,6 @@ import org.mifosng.platform.api.data.NewLoanData;
|
||||
import org.mifosng.platform.api.data.NoteData;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.api.data.SavingProductData;
|
||||
import org.mifosng.platform.api.errorhandling.InvalidJsonException;
|
||||
import org.mifosng.platform.api.errorhandling.UnsupportedParameterException;
|
||||
@@ -493,110 +490,6 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertAppUserDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final AppUserData... users) {
|
||||
|
||||
final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username", "firstname", "lastname", "email",
|
||||
"allowedOffices", "availableRoles", "selectedRoles"));
|
||||
|
||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||
|
||||
if (!responseParameters.isEmpty()) {
|
||||
if (!supportedParameters.containsAll(responseParameters)) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
|
||||
}
|
||||
|
||||
parameterNamesToSkip.addAll(supportedParameters);
|
||||
parameterNamesToSkip.removeAll(responseParameters);
|
||||
}
|
||||
|
||||
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
Gson gsonDeserializer = builder.create();
|
||||
|
||||
String json = "";
|
||||
if (users != null && users.length == 1) {
|
||||
json = gsonDeserializer.toJson(users[0]);
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(users);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertRoleDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final RoleData... roles) {
|
||||
final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "name", "description", "availablePermissions", "selectedPermissions"));
|
||||
|
||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||
|
||||
if (!responseParameters.isEmpty()) {
|
||||
if (!supportedParameters.containsAll(responseParameters)) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
|
||||
}
|
||||
|
||||
parameterNamesToSkip.addAll(supportedParameters);
|
||||
parameterNamesToSkip.removeAll(responseParameters);
|
||||
}
|
||||
|
||||
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
Gson gsonDeserializer = builder.create();
|
||||
|
||||
String json = "";
|
||||
if (roles != null && roles.length == 1) {
|
||||
json = gsonDeserializer.toJson(roles[0]);
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(roles);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertPermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final PermissionData... permissions) {
|
||||
final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "name", "description", "code"));
|
||||
|
||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||
|
||||
if (!responseParameters.isEmpty()) {
|
||||
if (!supportedParameters.containsAll(responseParameters)) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(responseParameters));
|
||||
}
|
||||
|
||||
parameterNamesToSkip.addAll(supportedParameters);
|
||||
parameterNamesToSkip.removeAll(responseParameters);
|
||||
}
|
||||
|
||||
ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
|
||||
|
||||
GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
Gson gsonDeserializer = builder.create();
|
||||
|
||||
String json = "";
|
||||
if (permissions != null && permissions.length == 1) {
|
||||
json = gsonDeserializer.toJson(permissions[0]);
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(permissions);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertOfficeDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeData... offices) {
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
package org.mifosng.platform.api.infrastructure;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
|
||||
public interface ApiJsonSerializerService {
|
||||
|
||||
String serializePermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<PermissionData> permissions);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<RoleData> roles);
|
||||
|
||||
String serializeRoleDataToJson(boolean prettyPrint, Set<String> responseParameters, RoleData role);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<AppUserData> users);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, AppUserData user);
|
||||
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
package org.mifosng.platform.api.infrastructure;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* Implementation of {@link ApiJsonSerializerService} that uses google-gson to serialize Java object representation into JSON.
|
||||
*/
|
||||
@Service
|
||||
public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerService {
|
||||
|
||||
private static final Set<String> PERMISSION_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description", "code"));
|
||||
private static final Set<String> ROLE_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("id", "name", "description", "availablePermissions", "selectedPermissions"));
|
||||
private static final Set<String> APP_USER_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "officeId", "officeName", "username", "firstname", "lastname", "email",
|
||||
"allowedOffices", "availableRoles", "selectedRoles"));
|
||||
|
||||
private final GoogleGsonSerializerHelper helper;
|
||||
|
||||
@Autowired
|
||||
public GoogleGsonApiJsonSerializerService(final GoogleGsonSerializerHelper helper) {
|
||||
this.helper = helper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializePermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final Collection<PermissionData> permissions) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(PERMISSION_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, permissions.toArray(new PermissionData[permissions.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeRoleDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final Collection<RoleData> roles) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(ROLE_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, roles.toArray(new RoleData[roles.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeRoleDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final RoleData role) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(ROLE_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, role);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeAppUserDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final Collection<AppUserData> users) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(APP_USER_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, users.toArray(new AppUserData[users.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeAppUserDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final AppUserData user) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(APP_USER_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, user);
|
||||
}
|
||||
}
|
||||
+62
@@ -0,0 +1,62 @@
|
||||
package org.mifosng.platform.api.infrastructure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.mifosng.platform.api.errorhandling.UnsupportedParameterException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
|
||||
/**
|
||||
* Helper class for serialization of java objects into JSON using google-gson.
|
||||
*/
|
||||
@Service
|
||||
public class GoogleGsonSerializerHelper {
|
||||
|
||||
public Gson createGsonBuilderWithParameterExclusionSerializationStrategy(
|
||||
final Set<String> supportedParameters,
|
||||
final boolean prettyPrint,
|
||||
final Set<String> responseParameters) {
|
||||
|
||||
final Set<String> parameterNamesToSkip = new HashSet<String>();
|
||||
|
||||
if (!responseParameters.isEmpty()) {
|
||||
|
||||
// strip out all know support parameters from expected response to
|
||||
// see if unsupported parameters requested for response.
|
||||
final Set<String> differentParametersDetectedSet = new HashSet<String>(responseParameters);
|
||||
differentParametersDetectedSet.removeAll(supportedParameters);
|
||||
|
||||
if (!differentParametersDetectedSet.isEmpty()) {
|
||||
throw new UnsupportedParameterException(new ArrayList<String>(differentParametersDetectedSet));
|
||||
}
|
||||
|
||||
parameterNamesToSkip.addAll(supportedParameters);
|
||||
parameterNamesToSkip.removeAll(responseParameters);
|
||||
}
|
||||
|
||||
final ExclusionStrategy strategy = new ParameterListExclusionStrategy(parameterNamesToSkip);
|
||||
|
||||
final GsonBuilder builder = new GsonBuilder().addSerializationExclusionStrategy(strategy);
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public String serializedJsonFrom(final Gson serializer, final Object[] dataObjects) {
|
||||
return serializer.toJson(dataObjects);
|
||||
}
|
||||
|
||||
public String serializedJsonFrom(final Gson serializer, final Object singleDataObject) {
|
||||
return serializer.toJson(singleDataObject);
|
||||
}
|
||||
}
|
||||
@@ -62,16 +62,13 @@ public class Role extends AbstractAuditableCustom<AppUser, Long> {
|
||||
|
||||
public RoleData toData() {
|
||||
|
||||
RoleData data = new RoleData(this.getId(), this.name, this.description);
|
||||
|
||||
Collection<PermissionData> rolePermissions = new ArrayList<PermissionData>();
|
||||
for (Permission permission : this.permissions) {
|
||||
PermissionData permissionData = permission.toData();
|
||||
rolePermissions.add(permissionData);
|
||||
}
|
||||
data.setSelectedPermissions(rolePermissions);
|
||||
|
||||
return data;
|
||||
return new RoleData(this.getId(), this.name, this.description, rolePermissions);
|
||||
}
|
||||
|
||||
public void update(final RoleCommand command, final List<Permission> selectedPermissions) {
|
||||
|
||||
+7
-15
@@ -79,9 +79,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
|
||||
List<RoleData> availableRoles = new ArrayList<RoleData>(this.roleReadPlatformService.retrieveAllRoles());
|
||||
|
||||
AppUserData userData = new AppUserData();
|
||||
userData.setAllowedOffices(offices);
|
||||
userData.setAvailableRoles(availableRoles);
|
||||
AppUserData userData = new AppUserData(offices, availableRoles);
|
||||
|
||||
return userData;
|
||||
}
|
||||
@@ -98,21 +96,17 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
|
||||
List<RoleData> availableRoles = new ArrayList<RoleData>(this.roleReadPlatformService.retrieveAllRoles());
|
||||
|
||||
List<RoleData> userRoleData = new ArrayList<RoleData>();
|
||||
List<RoleData> selectedUserRoles = new ArrayList<RoleData>();
|
||||
Set<Role> userRoles = user.getRoles();
|
||||
for (Role role : userRoles) {
|
||||
userRoleData.add(role.toData());
|
||||
selectedUserRoles.add(role.toData());
|
||||
}
|
||||
|
||||
availableRoles.removeAll(selectedUserRoles);
|
||||
|
||||
AppUserData userData = new AppUserData(user.getId(),
|
||||
user.getUsername(), user.getEmail(), user.getOffice().getId(), user.getOffice()
|
||||
.getName());
|
||||
userData.setFirstname(user.getFirstname());
|
||||
userData.setLastname(user.getLastname());
|
||||
|
||||
availableRoles.removeAll(userRoleData);
|
||||
userData.setAvailableRoles(availableRoles);
|
||||
userData.setSelectedRoles(userRoleData);
|
||||
.getName(), user.getFirstname(), user.getLastname(), availableRoles, selectedUserRoles);
|
||||
|
||||
return userData;
|
||||
}
|
||||
@@ -139,9 +133,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
||||
// FIXME - change sql query to join to get office id and name information.
|
||||
String officeName = fromOfficeList(this.offices, officeId);
|
||||
|
||||
AppUserData user = new AppUserData(id, username, email, officeId, officeName);
|
||||
user.setLastname(lastname);
|
||||
user.setFirstname(firstname);
|
||||
AppUserData user = new AppUserData(id, username, email, officeId, officeName, firstname, lastname, new ArrayList<RoleData>(), new ArrayList<RoleData>());
|
||||
|
||||
return user;
|
||||
}
|
||||
|
||||
+4
-1
@@ -2,8 +2,10 @@ package org.mifosng.platform.user.service;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mifosng.platform.api.data.PermissionData;
|
||||
import org.mifosng.platform.api.data.RoleData;
|
||||
import org.mifosng.platform.exceptions.RoleNotFoundException;
|
||||
import org.mifosng.platform.infrastructure.JdbcSupport;
|
||||
@@ -61,7 +63,8 @@ public class RoleReadPlatformServiceImpl implements RoleReadPlatformService {
|
||||
String name = rs.getString("name");
|
||||
String description = rs.getString("description");
|
||||
|
||||
return new RoleData(id, name, description);
|
||||
Collection<PermissionData> selectedPermissions = new ArrayList<PermissionData>(0);
|
||||
return new RoleData(id, name, description, selectedPermissions);
|
||||
}
|
||||
|
||||
public String schema() {
|
||||
|
||||
Reference in New Issue
Block a user