from MIFOSX-38 - update serialization of offices and office transactions.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
ALTER TABLE `m_deposit_account` ADD COLUMN `status_enum` smallint(5) NOT NULL AFTER `is_deleted`;
|
||||
ALTER TABLE `m_deposit_account` ADD COLUMN `status_enum` smallint(5) NOT NULL DEFAULT 0 AFTER `is_deleted`;
|
||||
|
||||
DROP TABLE IF EXISTS `m_deposit_account_transaction`;
|
||||
CREATE TABLE `m_deposit_account_transaction` (
|
||||
|
||||
+7
-10
@@ -11,7 +11,7 @@ import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.mifosng.platform.api.data.AuthenticatedUserData;
|
||||
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
|
||||
import org.mifosng.platform.api.infrastructure.ApiJsonSerializerService;
|
||||
import org.mifosng.platform.user.domain.AppUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@@ -34,8 +34,8 @@ public class AuthenticationApiResource {
|
||||
private DaoAuthenticationProvider customAuthenticationProvider;
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
|
||||
private ApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
@POST
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@Produces({MediaType.APPLICATION_JSON})
|
||||
@@ -45,22 +45,19 @@ public class AuthenticationApiResource {
|
||||
Authentication authenticationCheck = customAuthenticationProvider.authenticate(authentication);
|
||||
|
||||
Collection<String> permissions = new ArrayList<String>();
|
||||
AuthenticatedUserData authenticatedUserData = new AuthenticatedUserData(permissions);
|
||||
authenticatedUserData.setUsername(username);
|
||||
AuthenticatedUserData authenticatedUserData = new AuthenticatedUserData(username, permissions);
|
||||
|
||||
if (authenticationCheck.isAuthenticated()) {
|
||||
Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(authenticationCheck.getAuthorities());
|
||||
for (GrantedAuthority grantedAuthority : authorities) {
|
||||
permissions.add(grantedAuthority.getAuthority());
|
||||
}
|
||||
authenticatedUserData.setPermissions(permissions);
|
||||
authenticatedUserData.setAuthenticated(true);
|
||||
AppUser principal = (AppUser) authenticationCheck.getPrincipal();
|
||||
authenticatedUserData.setUserId(principal.getId());
|
||||
byte[] base64EncodedAuthenticationKey = Base64.encode(username + ":" + password);
|
||||
authenticatedUserData.setBase64EncodedAuthenticationKey(new String(base64EncodedAuthenticationKey));
|
||||
|
||||
authenticatedUserData = new AuthenticatedUserData(username, permissions, principal.getId(), new String(base64EncodedAuthenticationKey));
|
||||
}
|
||||
|
||||
return this.apiDataConversionService.convertAuthenticatedUserDataToJson(false, authenticatedUserData);
|
||||
return this.apiJsonSerializerService.serializeAuthenticatedUserDataToJson(false, authenticatedUserData);
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -18,6 +18,7 @@ import org.mifosng.platform.api.commands.BranchMoneyTransferCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.OfficeTransactionData;
|
||||
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.organisation.service.OfficeWritePlatformService;
|
||||
@@ -38,6 +39,9 @@ public class OfficeTransactionsApiResource {
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
|
||||
@Autowired
|
||||
private ApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
@GET
|
||||
@Path("template")
|
||||
@@ -55,7 +59,7 @@ public class OfficeTransactionsApiResource {
|
||||
|
||||
OfficeTransactionData officeTransactionData = this.readPlatformService.retrieveNewOfficeTransactionDetails();
|
||||
|
||||
return this.apiDataConversionService.convertOfficeTransactionDataToJson(prettyPrint, responseParameters, officeTransactionData);
|
||||
return this.apiJsonSerializerService.serializeOfficeTransactionDataToJson(prettyPrint, responseParameters, officeTransactionData);
|
||||
}
|
||||
|
||||
@POST
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.mifosng.platform.api;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
@@ -20,7 +21,9 @@ import javax.ws.rs.core.UriInfo;
|
||||
import org.mifosng.platform.api.commands.OfficeCommand;
|
||||
import org.mifosng.platform.api.data.EntityIdentifier;
|
||||
import org.mifosng.platform.api.data.OfficeData;
|
||||
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.organisation.service.OfficeWritePlatformService;
|
||||
@@ -41,6 +44,9 @@ public class OfficesApiResource {
|
||||
|
||||
@Autowired
|
||||
private ApiDataConversionService apiDataConversionService;
|
||||
|
||||
@Autowired
|
||||
private ApiJsonSerializerService apiJsonSerializerService;
|
||||
|
||||
@GET
|
||||
@Consumes({MediaType.APPLICATION_JSON})
|
||||
@@ -59,7 +65,7 @@ public class OfficesApiResource {
|
||||
|
||||
Collection<OfficeData> offices = this.readPlatformService.retrieveAllOffices();
|
||||
|
||||
return this.apiDataConversionService.convertOfficeDataToJson(prettyPrint, responseParameters, offices.toArray(new OfficeData[offices.size()]));
|
||||
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, responseParameters, offices);
|
||||
}
|
||||
|
||||
@GET
|
||||
@@ -74,9 +80,9 @@ public class OfficesApiResource {
|
||||
|
||||
boolean prettyPrint = ApiParameterHelper.prettyPrint(uriInfo.getQueryParameters());
|
||||
|
||||
OfficeData officeData = this.readPlatformService.retrieveNewOfficeTemplate();
|
||||
OfficeData office = this.readPlatformService.retrieveNewOfficeTemplate();
|
||||
|
||||
return this.apiDataConversionService.convertOfficeDataToJson(prettyPrint, typicalResponseParameters, officeData);
|
||||
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, typicalResponseParameters, office);
|
||||
}
|
||||
|
||||
@POST
|
||||
@@ -110,11 +116,12 @@ public class OfficesApiResource {
|
||||
|
||||
OfficeData office = this.readPlatformService.retrieveOffice(officeId);
|
||||
if (template) {
|
||||
office.setAllowedParents(this.readPlatformService.retrieveAllowedParents(officeId));
|
||||
List<OfficeLookup> allowedParents = this.readPlatformService.retrieveAllowedParents(officeId);
|
||||
office = OfficeData.appendedTemplate(office, allowedParents);
|
||||
responseParameters.add("allowedParents");
|
||||
}
|
||||
|
||||
return this.apiDataConversionService.convertOfficeDataToJson(prettyPrint, responseParameters, office);
|
||||
return this.apiJsonSerializerService.serializeOfficeDataToJson(prettyPrint, responseParameters, office);
|
||||
}
|
||||
|
||||
@PUT
|
||||
|
||||
+24
-35
@@ -1,29 +1,31 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Immutable data object for authentication.
|
||||
*/
|
||||
public class AuthenticatedUserData {
|
||||
|
||||
private String username;
|
||||
private Long userId;
|
||||
private String base64EncodedAuthenticationKey;
|
||||
private boolean authenticated = false;
|
||||
private Collection<String> permissions = new ArrayList<String>();
|
||||
private final String username;
|
||||
private final Long userId;
|
||||
private final String base64EncodedAuthenticationKey;
|
||||
private final boolean authenticated;
|
||||
private final Collection<String> permissions;
|
||||
|
||||
protected AuthenticatedUserData() {
|
||||
//
|
||||
}
|
||||
|
||||
public AuthenticatedUserData(final Collection<String> permissions) {
|
||||
public AuthenticatedUserData(final String username, final Collection<String> permissions) {
|
||||
this.username = username;
|
||||
this.userId = null;
|
||||
this.base64EncodedAuthenticationKey = null;
|
||||
this.authenticated = false;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
public Collection<String> getPermissions() {
|
||||
return this.permissions;
|
||||
}
|
||||
|
||||
public void setPermissions(final Collection<String> permissions) {
|
||||
public AuthenticatedUserData(final String username, final Collection<String> permissions, final Long userId, final String base64EncodedAuthenticationKey) {
|
||||
this.username = username;
|
||||
this.userId = userId;
|
||||
this.base64EncodedAuthenticationKey = base64EncodedAuthenticationKey;
|
||||
this.authenticated = true;
|
||||
this.permissions = permissions;
|
||||
}
|
||||
|
||||
@@ -31,32 +33,19 @@ public class AuthenticatedUserData {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public boolean isAuthenticated() {
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
public void setAuthenticated(boolean authenticated) {
|
||||
this.authenticated = authenticated;
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public String getBase64EncodedAuthenticationKey() {
|
||||
return base64EncodedAuthenticationKey;
|
||||
}
|
||||
|
||||
public void setBase64EncodedAuthenticationKey(
|
||||
String base64EncodedAuthenticationKey) {
|
||||
this.base64EncodedAuthenticationKey = base64EncodedAuthenticationKey;
|
||||
public boolean isAuthenticated() {
|
||||
return authenticated;
|
||||
}
|
||||
|
||||
public Long getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Long userId) {
|
||||
this.userId = userId;
|
||||
public Collection<String> getPermissions() {
|
||||
return permissions;
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,38 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Immutable data object for office data.
|
||||
*/
|
||||
public class OfficeData {
|
||||
|
||||
private Long id;
|
||||
private String name;
|
||||
private String nameDecorated;
|
||||
private String externalId;
|
||||
private LocalDate openingDate;
|
||||
private String hierarchy;
|
||||
private Long parentId;
|
||||
private String parentName;
|
||||
private final Long id;
|
||||
private final String name;
|
||||
private final String nameDecorated;
|
||||
private final String externalId;
|
||||
private final LocalDate openingDate;
|
||||
private final String hierarchy;
|
||||
private final Long parentId;
|
||||
private final String parentName;
|
||||
|
||||
private List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>();
|
||||
|
||||
public OfficeData() {
|
||||
//
|
||||
private final List<OfficeLookup> allowedParents;
|
||||
|
||||
public static OfficeData template(final List<OfficeLookup> parentLookups, final LocalDate defaultOpeningDate) {
|
||||
return new OfficeData(null, null, null, null, defaultOpeningDate, null, null, null, parentLookups);
|
||||
}
|
||||
|
||||
public static OfficeData appendedTemplate(final OfficeData office, final List<OfficeLookup> allowedParents) {
|
||||
return new OfficeData(office.getId(), office.getName(), office.getNameDecorated(), office.getExternalId(),
|
||||
office.getOpeningDate(), office.getHierarchy(), office.getParentId(), office.getParentName(), allowedParents);
|
||||
}
|
||||
|
||||
public OfficeData(final Long id, final String name,
|
||||
final String nameDecorated, final String externalId,
|
||||
final LocalDate openingDate, String hierarchy, final Long parentId,
|
||||
final String parentName) {
|
||||
final String parentName, final List<OfficeLookup> allowedParents) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.nameDecorated = nameDecorated;
|
||||
@@ -34,14 +41,15 @@ public class OfficeData {
|
||||
this.hierarchy = hierarchy;
|
||||
this.parentName = parentName;
|
||||
this.parentId = parentId;
|
||||
this.allowedParents = allowedParents;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return this.id;
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getNameDecorated() {
|
||||
@@ -49,62 +57,26 @@ public class OfficeData {
|
||||
}
|
||||
|
||||
public String getExternalId() {
|
||||
return this.externalId;
|
||||
return externalId;
|
||||
}
|
||||
|
||||
public LocalDate getOpeningDate() {
|
||||
return this.openingDate;
|
||||
}
|
||||
|
||||
public Long getParentId() {
|
||||
return this.parentId;
|
||||
}
|
||||
|
||||
public String getParentName() {
|
||||
return this.parentName;
|
||||
}
|
||||
|
||||
public void setId(final Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setNameDecorated(String nameDecorated) {
|
||||
this.nameDecorated = nameDecorated;
|
||||
}
|
||||
|
||||
public void setExternalId(final String externalId) {
|
||||
this.externalId = externalId;
|
||||
}
|
||||
|
||||
public void setOpeningDate(final LocalDate openingDate) {
|
||||
this.openingDate = openingDate;
|
||||
}
|
||||
|
||||
public void setParentName(final String parentName) {
|
||||
this.parentName = parentName;
|
||||
}
|
||||
|
||||
public void setParentId(final Long parentId) {
|
||||
this.parentId = parentId;
|
||||
return openingDate;
|
||||
}
|
||||
|
||||
public String getHierarchy() {
|
||||
return hierarchy;
|
||||
}
|
||||
|
||||
public void setHierarchy(String hierarchy) {
|
||||
this.hierarchy = hierarchy;
|
||||
public Long getParentId() {
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public String getParentName() {
|
||||
return parentName;
|
||||
}
|
||||
|
||||
public List<OfficeLookup> getAllowedParents() {
|
||||
return allowedParents;
|
||||
}
|
||||
|
||||
public void setAllowedParents(List<OfficeLookup> allowedParents) {
|
||||
this.allowedParents = allowedParents;
|
||||
}
|
||||
}
|
||||
+6
-17
@@ -1,15 +1,17 @@
|
||||
package org.mifosng.platform.api.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
|
||||
/**
|
||||
* Immutable data object for office transactions.
|
||||
*/
|
||||
public class OfficeTransactionData {
|
||||
|
||||
private LocalDate transactionDate;
|
||||
private List<CurrencyData> currencyOptions = new ArrayList<CurrencyData>();
|
||||
private List<OfficeLookup> allowedOffices = new ArrayList<OfficeLookup>();
|
||||
private final LocalDate transactionDate;
|
||||
private final List<CurrencyData> currencyOptions;
|
||||
private final List<OfficeLookup> allowedOffices;
|
||||
|
||||
public OfficeTransactionData(final LocalDate transactionDate, final List<OfficeLookup> allowedOffices, final List<CurrencyData> currencyOptions) {
|
||||
this.transactionDate = transactionDate;
|
||||
@@ -21,24 +23,11 @@ public class OfficeTransactionData {
|
||||
return transactionDate;
|
||||
}
|
||||
|
||||
public void setTransactionDate(LocalDate transactionDate) {
|
||||
this.transactionDate = transactionDate;
|
||||
}
|
||||
|
||||
public List<CurrencyData> getCurrencyOptions() {
|
||||
return currencyOptions;
|
||||
}
|
||||
|
||||
public void setCurrencyOptions(List<CurrencyData> currencyOptions) {
|
||||
this.currencyOptions = currencyOptions;
|
||||
}
|
||||
|
||||
public List<OfficeLookup> getAllowedOffices() {
|
||||
return allowedOffices;
|
||||
}
|
||||
|
||||
public void setAllowedOffices(List<OfficeLookup> allowedOffices) {
|
||||
this.allowedOffices = allowedOffices;
|
||||
}
|
||||
|
||||
}
|
||||
-9
@@ -22,7 +22,6 @@ 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.AuthenticatedUserData;
|
||||
import org.mifosng.platform.api.data.ChargeData;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
|
||||
@@ -37,15 +36,11 @@ import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
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.SavingProductData;
|
||||
|
||||
public interface ApiDataConversionService {
|
||||
|
||||
//
|
||||
String convertOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeTransactionData... officeTransactions);
|
||||
|
||||
String convertConfigurationDataToJson(boolean prettyPrint, Set<String> responseParameters, ConfigurationData... configuration);
|
||||
|
||||
String convertClientDataToJson(boolean prettyPrint, Set<String> responseParameters, ClientData... clients);
|
||||
@@ -76,8 +71,6 @@ public interface ApiDataConversionService {
|
||||
String convertAdditionalFieldsSetDataToJson(boolean prettyPrint, AdditionalFieldsSetData... additionalFields);
|
||||
|
||||
String convertGenericResultsetDataToJson(boolean prettyPrint, GenericResultsetData result);
|
||||
|
||||
String convertAuthenticatedUserDataToJson(boolean prettyPrint, AuthenticatedUserData authenticatedUserData);
|
||||
//
|
||||
|
||||
ChargeCommand convertJsonToChargeCommand(Long resourceIdentifier, String json);
|
||||
@@ -90,8 +83,6 @@ public interface ApiDataConversionService {
|
||||
|
||||
OfficeCommand convertJsonToOfficeCommand(Long resourceIdentifier, String json);
|
||||
|
||||
String convertOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeData... offices);
|
||||
|
||||
RoleCommand convertJsonToRoleCommand(Long resourceIdentifier, String json);
|
||||
|
||||
UserCommand convertJsonToUserCommand(Long resourceIdentifier, String json);
|
||||
|
||||
-88
@@ -39,7 +39,6 @@ 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.AuthenticatedUserData;
|
||||
import org.mifosng.platform.api.data.ChargeData;
|
||||
import org.mifosng.platform.api.data.ClientData;
|
||||
import org.mifosng.platform.api.data.ClientLoanAccountSummaryCollectionData;
|
||||
@@ -54,8 +53,6 @@ import org.mifosng.platform.api.data.LoanProductData;
|
||||
import org.mifosng.platform.api.data.LoanTransactionData;
|
||||
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.SavingProductData;
|
||||
import org.mifosng.platform.api.errorhandling.InvalidJsonException;
|
||||
import org.mifosng.platform.api.errorhandling.UnsupportedParameterException;
|
||||
@@ -82,20 +79,6 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
gsonConverter = new Gson();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertAuthenticatedUserDataToJson(final boolean prettyPrint, final AuthenticatedUserData authenticatedUserData) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
|
||||
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
Gson gsonDeserializer = builder.create();
|
||||
|
||||
return gsonDeserializer.toJson(authenticatedUserData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertGenericResultsetDataToJson(final boolean prettyPrint, final GenericResultsetData result) {
|
||||
GsonBuilder builder = new GsonBuilder();
|
||||
@@ -456,77 +439,6 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertOfficeTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeTransactionData... officeTransactions) {
|
||||
|
||||
final Set<String> supportedParameters = new HashSet<String>(Arrays.asList("transactionDate", "allowedOffices", "currencyOptions"));
|
||||
|
||||
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 (officeTransactions != null && officeTransactions.length == 1) {
|
||||
json = gsonDeserializer.toJson(officeTransactions[0]);
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(officeTransactions);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertOfficeDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeData... offices) {
|
||||
|
||||
Set<String> supportedParameters = new HashSet<String>(Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
|
||||
"hierarchy", "parentId", "parentName", "allowedParents"));
|
||||
|
||||
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 (offices != null && offices.length == 1) {
|
||||
json = gsonDeserializer.toJson(offices[0]);
|
||||
} else {
|
||||
json = gsonDeserializer.toJson(offices);
|
||||
}
|
||||
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertFundDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final FundData... funds) {
|
||||
|
||||
|
||||
+11
@@ -4,6 +4,9 @@ import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.AuthenticatedUserData;
|
||||
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;
|
||||
|
||||
@@ -18,5 +21,13 @@ public interface ApiJsonSerializerService {
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<AppUserData> users);
|
||||
|
||||
String serializeAppUserDataToJson(boolean prettyPrint, Set<String> responseParameters, AppUserData user);
|
||||
|
||||
String serializeAuthenticatedUserDataToJson(boolean prettyPrint, AuthenticatedUserData authenticatedUserData);
|
||||
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, Collection<OfficeData> offices);
|
||||
|
||||
String serializeOfficeDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeData office);
|
||||
|
||||
String serializeOfficeTransactionDataToJson(boolean prettyPrint, Set<String> responseParameters, OfficeTransactionData officeTransactionData);
|
||||
|
||||
}
|
||||
+33
-1
@@ -6,6 +6,9 @@ import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.mifosng.platform.api.data.AppUserData;
|
||||
import org.mifosng.platform.api.data.AuthenticatedUserData;
|
||||
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.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,7 +27,12 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
|
||||
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 static final Set<String> OFFICE_DATA_PARAMETERS = new HashSet<String>(
|
||||
Arrays.asList("id", "name", "nameDecorated", "externalId", "openingDate",
|
||||
"hierarchy", "parentId", "parentName", "allowedParents")
|
||||
);
|
||||
private static final Set<String> OFFICE_TRANSACTIONS_DATA_PARAMETERS = new HashSet<String>(Arrays.asList("transactionDate", "allowedOffices", "currencyOptions"));
|
||||
|
||||
private final GoogleGsonSerializerHelper helper;
|
||||
|
||||
@Autowired
|
||||
@@ -61,4 +69,28 @@ public class GoogleGsonApiJsonSerializerService implements ApiJsonSerializerServ
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(APP_USER_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeAuthenticatedUserDataToJson(final boolean prettyPrint, final AuthenticatedUserData authenticatedUserData) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilder(prettyPrint);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, authenticatedUserData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final Collection<OfficeData> offices) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(OFFICE_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, offices.toArray(new OfficeData[offices.size()]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeData office) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(OFFICE_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, office);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serializeOfficeTransactionDataToJson(final boolean prettyPrint, final Set<String> responseParameters, final OfficeTransactionData officeTransaction) {
|
||||
final Gson gsonDeserializer = helper.createGsonBuilderWithParameterExclusionSerializationStrategy(OFFICE_TRANSACTIONS_DATA_PARAMETERS, prettyPrint, responseParameters);
|
||||
return helper.serializedJsonFrom(gsonDeserializer, officeTransaction);
|
||||
}
|
||||
}
|
||||
+10
@@ -19,6 +19,16 @@ import com.google.gson.GsonBuilder;
|
||||
@Service
|
||||
public class GoogleGsonSerializerHelper {
|
||||
|
||||
public Gson createGsonBuilder(final boolean prettyPrint) {
|
||||
final GsonBuilder builder = new GsonBuilder();
|
||||
builder.registerTypeAdapter(LocalDate.class, new JodaLocalDateAdapter());
|
||||
builder.registerTypeAdapter(DateTime.class, new JodaDateTimeAdapter());
|
||||
if (prettyPrint) {
|
||||
builder.setPrettyPrinting();
|
||||
}
|
||||
return builder.create();
|
||||
}
|
||||
|
||||
public Gson createGsonBuilderWithParameterExclusionSerializationStrategy(
|
||||
final Set<String> supportedParameters,
|
||||
final boolean prettyPrint,
|
||||
|
||||
+4
-9
@@ -62,8 +62,8 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
Long parentId = JdbcSupport.getLong(rs, "parentId");
|
||||
String parentName = rs.getString("parentName");
|
||||
|
||||
return new OfficeData(id, name, nameDecorated, externalId,
|
||||
openingDate, hierarchy, parentId, parentName);
|
||||
List<OfficeLookup> allowedParents = new ArrayList<OfficeLookup>();
|
||||
return new OfficeData(id, name, nameDecorated, externalId, openingDate, hierarchy, parentId, parentName, allowedParents);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,11 +144,7 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(
|
||||
retrieveAllOfficesForLookup());
|
||||
|
||||
OfficeData officeData = new OfficeData();
|
||||
officeData.setAllowedParents(parentLookups);
|
||||
officeData.setOpeningDate(new LocalDate());
|
||||
|
||||
return officeData;
|
||||
return OfficeData.template(parentLookups, new LocalDate());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -156,8 +152,7 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
|
||||
|
||||
context.authenticatedUser();
|
||||
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(
|
||||
retrieveAllOfficesForLookup());
|
||||
List<OfficeLookup> parentLookups = new ArrayList<OfficeLookup>(retrieveAllOfficesForLookup());
|
||||
List<OfficeLookup> filterParentLookups = new ArrayList<OfficeLookup>();
|
||||
|
||||
for (OfficeLookup office : parentLookups) {
|
||||
|
||||
Reference in New Issue
Block a user