tidy up remaing commands for converstion from json.

This commit is contained in:
Keith Woodlock
2012-07-18 13:22:42 +01:00
parent 3f201d7ffa
commit e71e88a10b
13 changed files with 130 additions and 125 deletions
@@ -54,8 +54,8 @@ public class AdditionalFieldsApiResource {
private ApiJSONFormattingService jsonFormattingService;
@GET
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String datasets(@QueryParam("type") String type,
@Context UriInfo uriInfo) {
@@ -69,8 +69,8 @@ public class AdditionalFieldsApiResource {
@GET
@Path("{type}/{set}/{id}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String extraData(@PathParam("type") final String type,
@PathParam("set") final String set, @PathParam("id") final Long id,
@Context UriInfo uriInfo) {
@@ -98,8 +98,8 @@ public class AdditionalFieldsApiResource {
@POST
@Path("{type}/{set}/{id}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Response saveExtraData(@PathParam("type") final String type,
@PathParam("set") final String set, @PathParam("id") final Long id,
String reqbody) {
@@ -38,10 +38,10 @@ import org.springframework.stereotype.Component;
@Path("/clients")
@Component
@Scope("singleton")
public class ClientApiResource {
public class ClientsApiResource {
private final static Logger logger = LoggerFactory
.getLogger(ClientApiResource.class);
.getLogger(ClientsApiResource.class);
private String defaultFieldList = "joinedDate";
private String allowedFieldList = "allowedOffices";
@@ -219,12 +219,11 @@ public class ClientApiResource {
@Path("{clientId}/notes")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Response addNewClientNote(@PathParam("clientId") final Long clientId, final NoteCommand command) {
public Response addNewClientNote(@PathParam("clientId") final Long clientId, final String jsonRequestBody) {
command.setClientId(clientId);
EntityIdentifier identifier = this.clientWritePlatformService
.addClientNote(command);
NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(null, clientId, jsonRequestBody);
EntityIdentifier identifier = this.clientWritePlatformService.addClientNote(command);
return Response.ok().entity(identifier).build();
}
@@ -237,8 +236,7 @@ public class ClientApiResource {
@PathParam("clientId") final Long clientId,
@PathParam("noteId") final Long noteId, @Context final UriInfo uriInfo) {
NoteData note = this.clientReadPlatformService.retrieveClientNote(
clientId, noteId);
NoteData note = this.clientReadPlatformService.retrieveClientNote(clientId, noteId);
String selectedFields = "";
return this.jsonFormattingService.convertRequest(note, filterName,
@@ -251,11 +249,10 @@ public class ClientApiResource {
@Produces({MediaType.APPLICATION_JSON})
public Response updateClientNote(
@PathParam("clientId") final Long clientId,
@PathParam("noteId") final Long noteId, final NoteCommand command) {
command.setClientId(clientId);
command.setId(noteId);
@PathParam("noteId") final Long noteId, final String jsonRequestBody) {
NoteCommand command = this.apiDataConversionService.convertJsonToNoteCommand(noteId, clientId, jsonRequestBody);
EntityIdentifier identifier = this.clientWritePlatformService
.updateNote(command);
@@ -12,6 +12,7 @@ import javax.ws.rs.core.UriInfo;
import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
import org.mifosng.platform.api.data.ConfigurationData;
import org.mifosng.platform.api.infrastructure.ApiDataConversionService;
import org.mifosng.platform.api.infrastructure.ApiJSONFormattingService;
import org.mifosng.platform.configuration.service.ConfigurationReadPlatformService;
import org.mifosng.platform.configuration.service.ConfigurationWritePlatformService;
@@ -33,14 +34,17 @@ public class ConfigurationApiResource {
@Autowired
private ConfigurationWritePlatformService configurationWritePlatformService;
@Autowired
private ApiDataConversionService apiDataConversionService;
@Autowired
private ApiJSONFormattingService jsonFormattingService;
@GET
@Path("currency")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
public String retrieveCurrencyDataForConfiguration(@Context UriInfo uriInfo) {
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public String retrieveCurrencyDataForConfiguration(@Context final UriInfo uriInfo) {
ConfigurationData configurationData = this.configurationReadPlatformService
.retrieveCurrencyConfiguration();
@@ -53,13 +57,13 @@ public class ConfigurationApiResource {
@PUT
@Path("currency")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON })
public Response updateAllowedCurrenciesForOrganisation(
OrganisationCurrencyCommand command) {
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public Response updateAllowedCurrenciesForOrganisation(final String jsonRequestBody) {
this.configurationWritePlatformService
.updateOrganisationCurrencies(command);
OrganisationCurrencyCommand command = this.apiDataConversionService.convertJsonToOrganisationCurrencyCommand(jsonRequestBody);
this.configurationWritePlatformService.updateOrganisationCurrencies(command);
return Response.ok().entity(command).build();
}
@@ -1,10 +1,7 @@
package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement;
import org.joda.time.LocalDate;
@XmlRootElement
public class ClientCommand {
private final Long id;
@@ -1,60 +1,41 @@
package org.mifosng.platform.api.commands;
import javax.xml.bind.annotation.XmlRootElement;
/**
* Command used for add or edit notes.
* Immutable command used for create or update of notes.
*/
@XmlRootElement
public class NoteCommand {
private Long id;
private Long clientId;
private Long loanId;
private Long loanTransactionId;
private String note;
private final Long id;
private final Long clientId;
private final Long loanId;
private final Long loanTransactionId;
private final String note;
public NoteCommand() {
//
public NoteCommand(final Long id, Long clientId, final String note) {
this.id = id;
this.clientId = clientId;
this.loanId = null;
this.loanTransactionId = null;
this.note = note;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Long getClientId() {
return clientId;
}
public void setClientId(Long clientId) {
this.clientId = clientId;
}
public Long getLoanId() {
return loanId;
}
public void setLoanId(Long loanId) {
this.loanId = loanId;
}
public Long getLoanTransactionId() {
return loanTransactionId;
}
public void setLoanTransactionId(Long loanTransactionId) {
this.loanTransactionId = loanTransactionId;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
}
@@ -1,28 +1,17 @@
package org.mifosng.platform.api.commands;
import java.io.Serializable;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class OrganisationCurrencyCommand implements Serializable {
/**
* Immutable command for updating allowed currencies.
*/
public class OrganisationCurrencyCommand {
private String[] currencies;
public OrganisationCurrencyCommand() {
//
}
public OrganisationCurrencyCommand(final List<String> selectedCurrencyCodes) {
this.currencies = selectedCurrencyCodes.toArray(new String[selectedCurrencyCodes.size()]);
public OrganisationCurrencyCommand(final String[] currencies) {
this.currencies = currencies;
}
public String[] getCurrencies() {
return currencies;
}
public void setCurrencies(String... currencies) {
this.currencies = currencies;
}
}
@@ -1,39 +0,0 @@
package org.mifosng.platform.api.commands;
public class SubmitApproveDisburseLoanCommand {
private SubmitLoanApplicationCommand submitLoanApplicationCommand;
private LoanStateTransitionCommand approveLoanCommand;
private LoanStateTransitionCommand disburseLoanCommand;
public SubmitApproveDisburseLoanCommand() {
//
}
public SubmitLoanApplicationCommand getSubmitLoanApplicationCommand() {
return submitLoanApplicationCommand;
}
public void setSubmitLoanApplicationCommand(
SubmitLoanApplicationCommand submitLoanApplicationCommand) {
this.submitLoanApplicationCommand = submitLoanApplicationCommand;
}
public LoanStateTransitionCommand getApproveLoanCommand() {
return approveLoanCommand;
}
public void setApproveLoanCommand(
LoanStateTransitionCommand approveLoanCommand) {
this.approveLoanCommand = approveLoanCommand;
}
public LoanStateTransitionCommand getDisburseLoanCommand() {
return disburseLoanCommand;
}
public void setDisburseLoanCommand(
LoanStateTransitionCommand disburseLoanCommand) {
this.disburseLoanCommand = disburseLoanCommand;
}
}
@@ -3,9 +3,6 @@ package org.mifosng.platform.api.data;
import java.util.ArrayList;
import java.util.Collection;
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class AuthenticatedUserData {
private String username;
@@ -3,11 +3,8 @@ package org.mifosng.platform.api.data;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlRootElement;
import org.codehaus.jackson.map.annotate.JsonFilter;
@XmlRootElement
@JsonFilter("myFilter")
public class ClientLoanAccountSummaryCollectionData {
@@ -7,7 +7,9 @@ import org.mifosng.platform.api.commands.FundCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.NoteCommand;
import org.mifosng.platform.api.commands.OfficeCommand;
import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.platform.api.commands.UserCommand;
@@ -36,4 +38,8 @@ public interface ApiDataConversionService {
AdjustLoanTransactionCommand convertJsonToAdjustLoanTransactionCommand(
Long loanId, Long transactionId, String jsonRequestBody);
OrganisationCurrencyCommand convertJsonToOrganisationCurrencyCommand(String jsonRequestBody);
NoteCommand convertJsonToNoteCommand(Long resourceIdentifier, Long clientId, String jsonRequestBody);
}
@@ -24,7 +24,9 @@ import org.mifosng.platform.api.commands.FundCommand;
import org.mifosng.platform.api.commands.LoanProductCommand;
import org.mifosng.platform.api.commands.LoanStateTransitionCommand;
import org.mifosng.platform.api.commands.LoanTransactionCommand;
import org.mifosng.platform.api.commands.NoteCommand;
import org.mifosng.platform.api.commands.OfficeCommand;
import org.mifosng.platform.api.commands.OrganisationCurrencyCommand;
import org.mifosng.platform.api.commands.RoleCommand;
import org.mifosng.platform.api.commands.SubmitLoanApplicationCommand;
import org.mifosng.platform.api.commands.UserCommand;
@@ -634,6 +636,66 @@ public class ApiDataConversionServiceImpl implements ApiDataConversionService {
return new AdjustLoanTransactionCommand(loanId, transactionId, transactionDate, note, transactionAmount);
}
@Override
public NoteCommand convertJsonToNoteCommand(final Long noteId, final Long clientId, final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("note")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
String note = extractStringParameter("note", requestMap, modifiedParameters);
return new NoteCommand(noteId, clientId, note);
}
@Override
public OrganisationCurrencyCommand convertJsonToOrganisationCurrencyCommand(final String json) {
if (StringUtils.isBlank(json)) {
throw new InvalidJsonException();
}
Type typeOfMap = new TypeToken<Map<String, Object>>(){}.getType();
Map<String, Object> requestMap = gsonConverter.fromJson(json, typeOfMap);
Set<String> supportedParams = new HashSet<String>(
Arrays.asList("currencies")
);
checkForUnsupportedParameters(requestMap, supportedParams);
Set<String> modifiedParameters = new HashSet<String>();
// check array
JsonParser parser = new JsonParser();
String[] currencies = null;
JsonElement element = parser.parse(json);
if (element.isJsonObject()) {
JsonObject object = element.getAsJsonObject();
if (object.has("currencies")) {
modifiedParameters.add("currencies");
JsonArray array = object.get("currencies").getAsJsonArray();
currencies = new String[array.size()];
for (int i=0; i<array.size(); i++) {
currencies[i] = array.get(i).getAsString();
}
}
}
//
return new OrganisationCurrencyCommand(currencies);
}
private void checkForUnsupportedParameters(Map<String, ?> requestMap, Set<String> supportedParams) {
List<String> unsupportedParameterList = new ArrayList<String>();
@@ -12,6 +12,7 @@ import org.mifosng.platform.currency.domain.ApplicationCurrency;
import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosng.platform.organisation.domain.OrganisationCurrency;
import org.mifosng.platform.organisation.domain.OrganisationCurrencyRepository;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -22,12 +23,14 @@ public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements Confi
private final PlatformSecurityContext context;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final OrganisationCurrencyRepository organisationCurrencyRepository;
@Autowired
public ConfigurationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
final ApplicationCurrencyRepository applicationCurrencyRepository) {
final ApplicationCurrencyRepository applicationCurrencyRepository, final OrganisationCurrencyRepository organisationCurrencyRepository) {
this.context = context;
this.applicationCurrencyRepository = applicationCurrencyRepository;
this.organisationCurrencyRepository = organisationCurrencyRepository;
}
@Transactional
@@ -61,6 +64,9 @@ public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements Confi
}
}
this.organisationCurrencyRepository.deleteAll();
this.organisationCurrencyRepository.save(allowedCurrencies);
if (!dataValidationErrors.isEmpty()) {
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
@@ -0,0 +1,8 @@
package org.mifosng.platform.organisation.domain;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface OrganisationCurrencyRepository extends JpaRepository<OrganisationCurrency, Long>, JpaSpecificationExecutor<OrganisationCurrency> {
// no added behaviour
}