json serialization tidy up for user admin areas.
This commit is contained in:
+16
-9
@@ -1,5 +1,9 @@
|
|||||||
package org.mifosng.platform.api;
|
package org.mifosng.platform.api;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.POST;
|
import javax.ws.rs.POST;
|
||||||
@@ -11,10 +15,12 @@ import javax.ws.rs.core.Response;
|
|||||||
import javax.ws.rs.core.UriInfo;
|
import javax.ws.rs.core.UriInfo;
|
||||||
|
|
||||||
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||||
|
import org.mifosng.platform.api.data.AppUserData;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
||||||
|
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||||
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
||||||
import org.mifosng.platform.organisation.service.OfficeWritePlatformService;
|
import org.mifosng.platform.organisation.service.OfficeWritePlatformService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -44,16 +50,17 @@ public class OfficeTransactionsApiResource {
|
|||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String newOfficeTransactionDetails(@Context final UriInfo uriInfo) {
|
public String newOfficeTransactionDetails(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
OfficeTransactionData officeTransactionData = this.readPlatformService
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "transactionDate", "allowedOffices", "currencyOptions"));
|
||||||
.retrieveNewOfficeTransactionDetails();
|
|
||||||
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
if (responseParameters.isEmpty()) {
|
||||||
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
|
}
|
||||||
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
|
OfficeTransactionData officeTransactionData = this.readPlatformService.retrieveNewOfficeTransactionDetails();
|
||||||
|
|
||||||
String filterName = "myFilter";
|
return this.apiDataConversionService.convertOfficeTransactionDataToJson(prettyPrint, responseParameters, officeTransactionData);
|
||||||
String defaultFieldList = "transactionDate";
|
|
||||||
String allowedFieldList = "currencyOptions,allowedOffices";
|
|
||||||
String selectedFields = defaultFieldList + "," + allowedFieldList;
|
|
||||||
return this.jsonFormattingService.convertRequest(officeTransactionData,
|
|
||||||
filterName, allowedFieldList, selectedFields,
|
|
||||||
uriInfo.getQueryParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package org.mifosng.platform.api;
|
package org.mifosng.platform.api;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
@@ -9,7 +12,6 @@ import javax.ws.rs.PUT;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.QueryParam;
|
|
||||||
import javax.ws.rs.core.Context;
|
import javax.ws.rs.core.Context;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
@@ -20,7 +22,7 @@ import org.mifosng.platform.api.data.EntityIdentifier;
|
|||||||
import org.mifosng.platform.api.data.PermissionData;
|
import org.mifosng.platform.api.data.PermissionData;
|
||||||
import org.mifosng.platform.api.data.RoleData;
|
import org.mifosng.platform.api.data.RoleData;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||||
import org.mifosng.platform.user.service.PermissionReadPlatformService;
|
import org.mifosng.platform.user.service.PermissionReadPlatformService;
|
||||||
import org.mifosng.platform.user.service.RoleReadPlatformService;
|
import org.mifosng.platform.user.service.RoleReadPlatformService;
|
||||||
import org.mifosng.platform.user.service.RoleWritePlatformService;
|
import org.mifosng.platform.user.service.RoleWritePlatformService;
|
||||||
@@ -33,9 +35,6 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class RolesApiResource {
|
public class RolesApiResource {
|
||||||
|
|
||||||
private String allowedFieldList = "availablePermissions";
|
|
||||||
private String filterName = "roleFilter";
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RoleReadPlatformService roleReadPlatformService;
|
private RoleReadPlatformService roleReadPlatformService;
|
||||||
|
|
||||||
@@ -45,9 +44,6 @@ public class RolesApiResource {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private RoleWritePlatformService roleWritePlatformService;
|
private RoleWritePlatformService roleWritePlatformService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ApiJSONFormattingService jsonFormattingService;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiDataConversionService apiDataConversionService;
|
private ApiDataConversionService apiDataConversionService;
|
||||||
|
|
||||||
@@ -55,12 +51,18 @@ public class RolesApiResource {
|
|||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveAllRoles(@Context final UriInfo uriInfo) {
|
public String retrieveAllRoles(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "name", "description"));
|
||||||
|
|
||||||
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
if (responseParameters.isEmpty()) {
|
||||||
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
|
}
|
||||||
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
|
Collection<RoleData> roles = this.roleReadPlatformService.retrieveAllRoles();
|
||||||
|
|
||||||
String selectedFields = "id,name,description";
|
return this.apiDataConversionService.convertRoleDataToJson(prettyPrint, responseParameters, roles.toArray(new RoleData[roles.size()]));
|
||||||
return this.jsonFormattingService.convertRequest(roles, filterName,
|
|
||||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -69,14 +71,20 @@ public class RolesApiResource {
|
|||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveNewRoleDetails(@Context final UriInfo uriInfo) {
|
public String retrieveNewRoleDetails(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "name", "description", "availablePermissions", "selectedPermissions"));
|
||||||
|
|
||||||
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
if (responseParameters.isEmpty()) {
|
||||||
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
|
}
|
||||||
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
Collection<PermissionData> allPermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
Collection<PermissionData> allPermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||||
|
|
||||||
RoleData role = new RoleData();
|
RoleData role = new RoleData();
|
||||||
role.setAvailablePermissions(allPermissions);
|
role.setAvailablePermissions(allPermissions);
|
||||||
|
|
||||||
String selectedFields = allowedFieldList;
|
return this.apiDataConversionService.convertRoleDataToJson(prettyPrint, responseParameters, role);
|
||||||
return this.jsonFormattingService.convertRequest(role, filterName,
|
|
||||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
@@ -95,21 +103,29 @@ public class RolesApiResource {
|
|||||||
@Path("{roleId}")
|
@Path("{roleId}")
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveRole(@PathParam("roleId") final Long roleId,
|
public String retrieveRole(@PathParam("roleId") final Long roleId, @Context final UriInfo uriInfo) {
|
||||||
@QueryParam("template") final String template, @Context final UriInfo uriInfo) {
|
|
||||||
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "name", "description"));
|
||||||
|
|
||||||
|
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());
|
||||||
|
|
||||||
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
RoleData role = this.roleReadPlatformService.retrieveRole(roleId);
|
||||||
|
|
||||||
if (template != null && template.equalsIgnoreCase("true")) {
|
if (template) {
|
||||||
Collection<PermissionData> availablePermissions = this.permissionReadPlatformService
|
Collection<PermissionData> availablePermissions = this.permissionReadPlatformService.retrieveAllPermissions();
|
||||||
.retrieveAllPermissions();
|
|
||||||
availablePermissions.removeAll(role.getSelectedPermissions());
|
availablePermissions.removeAll(role.getSelectedPermissions());
|
||||||
role.setAvailablePermissions(availablePermissions);
|
role.setAvailablePermissions(availablePermissions);
|
||||||
|
|
||||||
|
responseParameters.add("availablePermissions");
|
||||||
|
responseParameters.add("selectedPermissions");
|
||||||
}
|
}
|
||||||
|
|
||||||
String selectedFields = "";
|
return this.apiDataConversionService.convertRoleDataToJson(prettyPrint, responseParameters, role);
|
||||||
return this.jsonFormattingService.convertRequest(role, filterName,
|
|
||||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package org.mifosng.platform.api;
|
package org.mifosng.platform.api;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
import javax.ws.rs.Consumes;
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
@@ -18,8 +23,10 @@ import javax.ws.rs.core.UriInfo;
|
|||||||
import org.mifosng.platform.api.commands.UserCommand;
|
import org.mifosng.platform.api.commands.UserCommand;
|
||||||
import org.mifosng.platform.api.data.AppUserData;
|
import org.mifosng.platform.api.data.AppUserData;
|
||||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
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.ApiDataConversionService;
|
||||||
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
|
import org.mifosng.platform.api.infrastructure.ApiParameterHelper;
|
||||||
|
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
|
||||||
import org.mifosng.platform.user.service.AppUserReadPlatformService;
|
import org.mifosng.platform.user.service.AppUserReadPlatformService;
|
||||||
import org.mifosng.platform.user.service.AppUserWritePlatformService;
|
import org.mifosng.platform.user.service.AppUserWritePlatformService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -31,31 +38,34 @@ import org.springframework.stereotype.Component;
|
|||||||
@Scope("singleton")
|
@Scope("singleton")
|
||||||
public class UsersApiResource {
|
public class UsersApiResource {
|
||||||
|
|
||||||
private String allowedFieldList = "allowedOffices,availableRoles";
|
|
||||||
private String filterName = "userFilter";
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AppUserReadPlatformService appUserReadPlatformService;
|
private AppUserReadPlatformService appUserReadPlatformService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OfficeReadPlatformService officeReadPlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private AppUserWritePlatformService appUserWritePlatformService;
|
private AppUserWritePlatformService appUserWritePlatformService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ApiDataConversionService apiDataConversionService;
|
private ApiDataConversionService apiDataConversionService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private ApiJSONFormattingService jsonFormattingService;
|
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveUsers(@Context final UriInfo uriInfo) {
|
public String retrieveUsers(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username", "firstname", "lastname", "email"));
|
||||||
|
|
||||||
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
if (responseParameters.isEmpty()) {
|
||||||
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
|
}
|
||||||
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
Collection<AppUserData> users = this.appUserReadPlatformService.retrieveAllUsers();
|
Collection<AppUserData> users = this.appUserReadPlatformService.retrieveAllUsers();
|
||||||
|
|
||||||
String selectedFields = "id,officeId,officeName,username,firstname,lastname,email";
|
return this.apiDataConversionService.convertAppUserDataToJson(prettyPrint, responseParameters, users.toArray(new AppUserData[users.size()]));
|
||||||
return this.jsonFormattingService.convertRequest(users, filterName,
|
|
||||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -63,12 +73,26 @@ public class UsersApiResource {
|
|||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String retrieveUser(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) {
|
public String retrieveUser(@PathParam("userId") final Long userId, @Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username", "firstname", "lastname", "email"));
|
||||||
|
|
||||||
|
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);
|
AppUserData user = this.appUserReadPlatformService.retrieveUser(userId);
|
||||||
|
if (template) {
|
||||||
String selectedFields = "";
|
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(this.officeReadPlatformService.retrieveAllOfficesForLookup());
|
||||||
return this.jsonFormattingService.convertRequest(user, filterName,
|
user.setAllowedOffices(offices);
|
||||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
responseParameters.add("allowedOffices");
|
||||||
|
responseParameters.add("availableRoles");
|
||||||
|
responseParameters.add("selectedRoles");
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.apiDataConversionService.convertAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@@ -76,13 +100,19 @@ public class UsersApiResource {
|
|||||||
@Consumes({MediaType.APPLICATION_JSON})
|
@Consumes({MediaType.APPLICATION_JSON})
|
||||||
@Produces({MediaType.APPLICATION_JSON})
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
public String newUserDetails(@Context final UriInfo uriInfo) {
|
public String newUserDetails(@Context final UriInfo uriInfo) {
|
||||||
|
|
||||||
|
Set<String> typicalResponseParameters = new HashSet<String>(Arrays.asList("id", "officeId", "officeName", "username", "firstname", "lastname", "email",
|
||||||
|
"allowedOffices", "availableRoles", "selectedRoles"));
|
||||||
|
|
||||||
|
Set<String> responseParameters = ApiParameterHelper.extractFieldsForResponseIfProvided(uriInfo.getQueryParameters());
|
||||||
|
if (responseParameters.isEmpty()) {
|
||||||
|
responseParameters.addAll(typicalResponseParameters);
|
||||||
|
}
|
||||||
|
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||||
|
|
||||||
|
AppUserData user = this.appUserReadPlatformService.retrieveNewUserDetails();
|
||||||
|
|
||||||
AppUserData newUser = this.appUserReadPlatformService
|
return this.apiDataConversionService.convertAppUserDataToJson(prettyPrint, responseParameters, user);
|
||||||
.retrieveNewUserDetails();
|
|
||||||
|
|
||||||
String selectedFields = allowedFieldList;
|
|
||||||
return this.jsonFormattingService.convertRequest(newUser, filterName,
|
|
||||||
allowedFieldList, selectedFields, uriInfo.getQueryParameters());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@POST
|
@POST
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ package org.mifosng.platform.api.data;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
|
||||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
|
||||||
|
|
||||||
@JsonIgnoreProperties({ "orgId" })
|
|
||||||
@JsonFilter("userFilter")
|
|
||||||
public class AppUserData {
|
public class AppUserData {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|||||||
@@ -3,11 +3,6 @@ package org.mifosng.platform.api.data;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
|
|
||||||
import org.codehaus.jackson.map.annotate.JsonFilter;
|
|
||||||
|
|
||||||
@JsonIgnoreProperties({ "orgId" })
|
|
||||||
@JsonFilter("roleFilter")
|
|
||||||
public class RoleData {
|
public class RoleData {
|
||||||
|
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|||||||
+9
@@ -15,14 +15,23 @@ import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
|
|||||||
import org.mifosng.platform.api.commands.RoleCommand;
|
import org.mifosng.platform.api.commands.RoleCommand;
|
||||||
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
||||||
import org.mifosng.platform.api.commands.UserCommand;
|
import org.mifosng.platform.api.commands.UserCommand;
|
||||||
|
import org.mifosng.platform.api.data.AppUserData;
|
||||||
import org.mifosng.platform.api.data.FundData;
|
import org.mifosng.platform.api.data.FundData;
|
||||||
import org.mifosng.platform.api.data.OfficeData;
|
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.PermissionData;
|
||||||
|
import org.mifosng.platform.api.data.RoleData;
|
||||||
|
|
||||||
public interface ApiDataConversionService {
|
public interface ApiDataConversionService {
|
||||||
|
|
||||||
//
|
//
|
||||||
String convertPermissionDataToJson(boolean prettyPrint, Set<String> responseParameters, PermissionData... permissions);
|
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);
|
||||||
//
|
//
|
||||||
|
|
||||||
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
|
FundCommand convertJsonToFundCommand(Long resourceIdentifier, String json);
|
||||||
|
|||||||
+65
@@ -31,9 +31,12 @@ import org.mifosng.platform.api.commands.RoleCommand;
|
|||||||
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
|
||||||
import org.mifosng.platform.api.commands.UserCommand;
|
import org.mifosng.platform.api.commands.UserCommand;
|
||||||
import org.mifosng.platform.api.data.ApiParameterError;
|
import org.mifosng.platform.api.data.ApiParameterError;
|
||||||
|
import org.mifosng.platform.api.data.AppUserData;
|
||||||
import org.mifosng.platform.api.data.FundData;
|
import org.mifosng.platform.api.data.FundData;
|
||||||
import org.mifosng.platform.api.data.OfficeData;
|
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.PermissionData;
|
||||||
|
import org.mifosng.platform.api.data.RoleData;
|
||||||
import org.mifosng.platform.api.errorhandling.InvalidJsonException;
|
import org.mifosng.platform.api.errorhandling.InvalidJsonException;
|
||||||
import org.mifosng.platform.api.errorhandling.UnsupportedParameterException;
|
import org.mifosng.platform.api.errorhandling.UnsupportedParameterException;
|
||||||
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
|
||||||
@@ -59,6 +62,68 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
|||||||
gsonConverter = new Gson();
|
gsonConverter = new Gson();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertOfficeTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeTransactionData... officeTransactions) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertAppUserDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final AppUserData... users) {
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
return gsonDeserializer.toJson(users);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String convertRoleDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final RoleData... roles) {
|
||||||
|
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();
|
||||||
|
|
||||||
|
return gsonDeserializer.toJson(roles);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String convertPermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final PermissionData... permissions) {
|
public String convertPermissionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final PermissionData... permissions) {
|
||||||
Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
|
Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
|
||||||
|
|||||||
+2
-6
@@ -91,15 +91,13 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
|||||||
|
|
||||||
context.authenticatedUser();
|
context.authenticatedUser();
|
||||||
|
|
||||||
List<OfficeLookup> offices = new ArrayList<OfficeLookup>(officeReadPlatformService.retrieveAllOfficesForLookup());
|
|
||||||
|
|
||||||
List<RoleData> availableRoles = new ArrayList<RoleData>(this.roleReadPlatformService.retrieveAllRoles());
|
|
||||||
|
|
||||||
AppUser user = this.appUserRepository.findOne(userId);
|
AppUser user = this.appUserRepository.findOne(userId);
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new UserNotFoundException(userId);
|
throw new UserNotFoundException(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<RoleData> availableRoles = new ArrayList<RoleData>(this.roleReadPlatformService.retrieveAllRoles());
|
||||||
|
|
||||||
List<RoleData> userRoleData = new ArrayList<RoleData>();
|
List<RoleData> userRoleData = new ArrayList<RoleData>();
|
||||||
Set<Role> userRoles = user.getRoles();
|
Set<Role> userRoles = user.getRoles();
|
||||||
for (Role role : userRoles) {
|
for (Role role : userRoles) {
|
||||||
@@ -112,8 +110,6 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic
|
|||||||
userData.setFirstname(user.getFirstname());
|
userData.setFirstname(user.getFirstname());
|
||||||
userData.setLastname(user.getLastname());
|
userData.setLastname(user.getLastname());
|
||||||
|
|
||||||
userData.setAllowedOffices(offices);
|
|
||||||
|
|
||||||
availableRoles.removeAll(userRoleData);
|
availableRoles.removeAll(userRoleData);
|
||||||
userData.setAvailableRoles(availableRoles);
|
userData.setAvailableRoles(availableRoles);
|
||||||
userData.setSelectedRoles(userRoleData);
|
userData.setSelectedRoles(userRoleData);
|
||||||
|
|||||||
Reference in New Issue
Block a user