From 3850cd9fb9ff29be48909de1df502a898ae4b18f Mon Sep 17 00:00:00 2001 From: Keith Woodlock Date: Mon, 11 Feb 2013 19:48:45 +0000 Subject: [PATCH] tidy up some bits around deposit products for example going forward. --- api-docs/apiLive.htm | 118 ------------------ .../api/DepositProductsApiResource.java | 59 +++++---- ...WritePlatformServiceJpaRepositoryImpl.java | 16 ++- 3 files changed, 48 insertions(+), 145 deletions(-) diff --git a/api-docs/apiLive.htm b/api-docs/apiLive.htm index 6589ef81a..ee038427c 100644 --- a/api-docs/apiLive.htm +++ b/api-docs/apiLive.htm @@ -919,124 +919,6 @@ -
-

Account

-
-
- - - - - - - - - - - - - - - - -
- - - - -
RESOURCES
-
- - - - - - -
POST
create/complex - update
- - - - - - -
GET
read
- - - - - - -
PUT
update
- - - - - - -
DELETE
delete
Not Yet Available
-
-
-
-
-

Group

-
-
- - - - - - - - - - - - - - - - -
- - - - -
RESOURCES
-
- - - - - - -
POST
create/complex - update
- - - - - - -
GET
read
- - - - - - -
PUT
update
- - - - - - -
DELETE
delete
Not Yet Available
-
-
-

Savings

diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java index 10d474c9b..7c80133b6 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/api/DepositProductsApiResource.java @@ -16,12 +16,13 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; import org.mifosplatform.infrastructure.core.api.ApiParameterHelper; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.core.data.EnumOptionData; +import org.mifosplatform.infrastructure.core.serialization.DefaultToApiJsonSerializer; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.data.CurrencyData; import org.mifosplatform.organisation.monetary.service.CurrencyReadPlatformService; @@ -44,56 +45,66 @@ public class DepositProductsApiResource { private final String entityType = "DEPOSITPRODUCT"; - @Autowired - private DepositProductReadPlatformService depositProductReadPlatformService; + private final PlatformSecurityContext context; + private final DepositProductReadPlatformService depositProductReadPlatformService; + private final CurrencyReadPlatformService currencyReadPlatformService; + private final DepositProductWritePlatformService depositProductWritePlatformService; + private final PortfolioApiDataConversionService apiDataConversionService; + private final PortfolioApiJsonSerializerService apiJsonSerializerService; + private final DefaultToApiJsonSerializer toApiJsonSerializer; @Autowired - private CurrencyReadPlatformService currencyReadPlatformService; - - @Autowired - private DepositProductWritePlatformService depositProductWritePlatformService; - - @Autowired - private PortfolioApiDataConversionService apiDataConversionService; - - @Autowired - private PortfolioApiJsonSerializerService apiJsonSerializerService; - - @Autowired - private PlatformSecurityContext context; + public DepositProductsApiResource(final PlatformSecurityContext context, + final DepositProductReadPlatformService depositProductReadPlatformService, + final CurrencyReadPlatformService currencyReadPlatformService, + final DepositProductWritePlatformService depositProductWritePlatformService, + final PortfolioApiDataConversionService apiDataConversionService, + final PortfolioApiJsonSerializerService apiJsonSerializerService, + final DefaultToApiJsonSerializer toApiJsonSerializer) { + this.context = context; + this.depositProductReadPlatformService = depositProductReadPlatformService; + this.currencyReadPlatformService = currencyReadPlatformService; + this.depositProductWritePlatformService = depositProductWritePlatformService; + this.apiDataConversionService = apiDataConversionService; + this.apiJsonSerializerService = apiJsonSerializerService; + this.toApiJsonSerializer = toApiJsonSerializer; + } @POST @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public Response createDepositProduct(final String jsonRequestBody) { + public String createDepositProduct(final String jsonRequestBody) { final DepositProductCommand command = this.apiDataConversionService.convertJsonToDepositProductCommand(null, jsonRequestBody); - CommandProcessingResult entityIdentifier = this.depositProductWritePlatformService.createDepositProduct(command); + final CommandProcessingResult result = this.depositProductWritePlatformService.createDepositProduct(command); - return Response.ok().entity(entityIdentifier).build(); + return this.toApiJsonSerializer.serialize(result); } @PUT @Path("{productId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public Response updateDepositProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) { + public String updateDepositProduct(@PathParam("productId") final Long productId, final String jsonRequestBody) { final DepositProductCommand command = this.apiDataConversionService.convertJsonToDepositProductCommand(productId, jsonRequestBody); - CommandProcessingResult entityIdentifier = this.depositProductWritePlatformService.updateDepositProduct(command); - return Response.ok().entity(entityIdentifier).build(); + final CommandProcessingResult result = this.depositProductWritePlatformService.updateDepositProduct(command); + + return this.toApiJsonSerializer.serialize(result); } @DELETE @Path("{productId}") @Consumes({ MediaType.APPLICATION_JSON }) @Produces({ MediaType.APPLICATION_JSON }) - public Response deleteDepositProduct(@PathParam("productId") final Long productId) { + public String deleteDepositProduct(@PathParam("productId") final Long productId) { this.depositProductWritePlatformService.deleteDepositProduct(productId); - return Response.ok(new CommandProcessingResult(productId)).build(); + final CommandProcessingResult result = new CommandProcessingResultBuilder().withEntityId(productId).build(); + + return this.toApiJsonSerializer.serialize(result); } @GET diff --git a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java index 068b3502a..e1a35ee21 100644 --- a/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosplatform/portfolio/savingsdepositproduct/service/DepositProductWritePlatformServiceJpaRepositoryImpl.java @@ -1,6 +1,7 @@ package org.mifosplatform.portfolio.savingsdepositproduct.service; import org.mifosplatform.infrastructure.core.data.CommandProcessingResult; +import org.mifosplatform.infrastructure.core.data.CommandProcessingResultBuilder; import org.mifosplatform.infrastructure.core.exception.PlatformDataIntegrityException; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.organisation.monetary.domain.MonetaryCurrency; @@ -70,7 +71,9 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo command.isLockinPeriodAllowed(), command.getLockinPeriod(), lockinPeriodType); this.depositProductRepository.save(product); - return new CommandProcessingResult(product.getId()); + return new CommandProcessingResultBuilder() // + .withEntityId(product.getId()) // + .build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); return new CommandProcessingResult(Long.valueOf(-1)); @@ -101,7 +104,10 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo product.update(command, interestCompoundingFrequency, lockinPeriodType); this.depositProductRepository.save(product); - return new CommandProcessingResult(Long.valueOf(product.getId())); + + return new CommandProcessingResultBuilder() // + .withEntityId(product.getId()) // + .build(); } catch (DataIntegrityViolationException dve) { handleDataIntegrityIssues(command, dve); return new CommandProcessingResult(Long.valueOf(-1)); @@ -116,7 +122,11 @@ public class DepositProductWritePlatformServiceJpaRepositoryImpl implements Depo DepositProduct product = this.depositProductRepository.findOne(productId); if (product == null) { throw new DepositProductNotFoundException(productId); } product.delete(); + this.depositProductRepository.save(product); - return new CommandProcessingResult(Long.valueOf(product.getId())); + + return new CommandProcessingResultBuilder() // + .withEntityId(product.getId()) // + .build(); } } \ No newline at end of file