diff --git a/mifosng-db/patches-beta-3-heavens-family/WIPdbchanges.sql b/mifosng-db/patches-beta-3-heavens-family/WIPdbchanges.sql deleted file mode 100644 index 0977cfdad..000000000 --- a/mifosng-db/patches-beta-3-heavens-family/WIPdbchanges.sql +++ /dev/null @@ -1,7 +0,0 @@ -/* remove column org_id */ -ALTER TABLE `portfolio_client` DROP FOREIGN KEY `FKCE00CAB354DF2770`; -ALTER TABLE `portfolio_client` - DROP COLUMN `org_id` , - DROP INDEX `org_id` , - ADD INDEX `external_id` (`external_id` ASC) , - DROP INDEX `FKCE00CAB354DF2770`; \ No newline at end of file diff --git a/mifosng-db/patches-beta-3-heavens-family/patch-0007-remove-organisations.sql b/mifosng-db/patches-beta-3-heavens-family/patch-0007-remove-organisations.sql index c1a0d1b75..cc566744d 100644 --- a/mifosng-db/patches-beta-3-heavens-family/patch-0007-remove-organisations.sql +++ b/mifosng-db/patches-beta-3-heavens-family/patch-0007-remove-organisations.sql @@ -8,6 +8,18 @@ DROP INDEX `externalid_org`, ADD UNIQUE INDEX `externalid_org` (`external_id` ASC), DROP INDEX `FK2291C47754DF2770`; +ALTER TABLE `portfolio_client` DROP FOREIGN KEY `FKCE00CAB354DF2770`; +ALTER TABLE `portfolio_client` + DROP COLUMN `org_id` , + DROP INDEX `org_id` , + ADD UNIQUE INDEX `external_id` (`external_id` ASC) , + DROP INDEX `FKCE00CAB354DF2770`; + +ALTER TABLE `portfolio_client` + DROP INDEX `external_id`, + ADD UNIQUE INDEX `external_id` (`external_id` ASC); + + ALTER TABLE `org_fund` DROP FOREIGN KEY `FK4E56DB4054DF2770` ; ALTER TABLE `org_fund` DROP COLUMN `org_id` , DROP INDEX `fund_name_org` , ADD UNIQUE INDEX `fund_name_org` (`name` ASC) , DROP INDEX `fund_externalid_org` , ADD UNIQUE INDEX `fund_externalid_org` (`external_id` ASC) , DROP INDEX `FK4E56DB4054DF2770` ; diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java index eddab3696..0df49f8fd 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeTransactionsApiResource.java @@ -8,20 +8,17 @@ import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; 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.apache.commons.lang.StringUtils; import org.joda.time.LocalDate; 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.ApiJSONFormattingService; -import org.mifosng.platform.exceptions.UnrecognizedQueryParamException; import org.mifosng.platform.organisation.service.OfficeReadPlatformService; import org.mifosng.platform.organisation.service.OfficeWritePlatformService; import org.springframework.beans.factory.annotation.Autowired; @@ -63,11 +60,10 @@ public class OfficeTransactionsApiResource { uriInfo.getQueryParameters()); } - @POST @Consumes({MediaType.APPLICATION_JSON}) @Produces({MediaType.APPLICATION_JSON}) - public Response transferMoneyFrom(@QueryParam("command") final String commandParam, final BranchMoneyTransferCommand command) { + public Response transferMoneyFrom(final BranchMoneyTransferCommand command) { LocalDate transactionLocalDate = apiDataConversionService.convertFrom(command.getTransactionDate(), "transactionDate", command.getDateFormat()); command.setTransactionLocalDate(transactionLocalDate); @@ -77,25 +73,7 @@ public class OfficeTransactionsApiResource { BigDecimal transactionAmountValue = apiDataConversionService.convertFrom(command.getTransactionAmount(), "transactionAmount", clientLocale); command.setTransactionAmountValue(transactionAmountValue); - Response response = null; - - if (is(commandParam, "intra-transfer")) { - Long id = this.writePlatformService.interBranchMoneyTransfer(command); - response = Response.ok().entity(new EntityIdentifier(id)).build(); - } else if (is(commandParam, "external-transfer")) { - Long id = this.writePlatformService.externalBranchMoneyTransfer(command); - response = Response.ok().entity(new EntityIdentifier(id)).build(); - } - - if (response == null) { - throw new UnrecognizedQueryParamException("command", commandParam); - } - - return response; - } - - private boolean is(final String commandParam, final String commandValue) { - return StringUtils.isNotBlank(commandParam) - && commandParam.trim().equalsIgnoreCase(commandValue); + Long id = this.writePlatformService.externalBranchMoneyTransfer(command); + return Response.ok().entity(new EntityIdentifier(id)).build(); } } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/BranchMoneyTransferCommandValidator.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/BranchMoneyTransferCommandValidator.java index e8878608b..4841cb097 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/BranchMoneyTransferCommandValidator.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/BranchMoneyTransferCommandValidator.java @@ -16,30 +16,15 @@ public class BranchMoneyTransferCommandValidator { this.command = command; } - public void validateInterBranchTransfer() { - - List dataValidationErrors = new ArrayList(); - - DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office.money.transfer"); - - baseDataValidator.reset().parameter("fromOfficeId").value(command.getFromOfficeId()).notNull(); - baseDataValidator.reset().parameter("toOfficeId").value(command.getToOfficeId()).notNull(); - baseDataValidator.reset().parameter("transactionDate").value(command.getTransactionLocalDate()).notNull(); - baseDataValidator.reset().parameter("currencyCode").value(command.getCurrencyCode()).notBlank(); - baseDataValidator.reset().parameter("transactionAmount").value(command.getTransactionAmountValue()).notNull(); - baseDataValidator.reset().parameter("description").value(command.getDescription()).notExceedingLengthOf(100); - - if (!dataValidationErrors.isEmpty()) { - throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors); - } - } - public void validateExternalBranchTransfer() { List dataValidationErrors = new ArrayList(); DataValidatorBuilder baseDataValidator = new DataValidatorBuilder(dataValidationErrors).resource("office.money.transfer"); + baseDataValidator.reset().parameter("fromOfficeId").value(command.getFromOfficeId()).greaterThanZero(); + baseDataValidator.reset().parameter("toOfficeId").value(command.getToOfficeId()).greaterThanZero(); + if (command.getFromOfficeId() == null) { baseDataValidator.reset().parameter("toOfficeId").value(command.getToOfficeId()).notNull(); } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java index c57c00859..00dac201c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformService.java @@ -12,9 +12,6 @@ public interface OfficeWritePlatformService { @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") Long updateOffice(final OfficeCommand command); - @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") - Long interBranchMoneyTransfer(BranchMoneyTransferCommand command); - @PreAuthorize(value = "hasRole('ORGANISATION_ADMINISTRATION_SUPER_USER_ROLE')") Long externalBranchMoneyTransfer(BranchMoneyTransferCommand command); } \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformServiceJpaRepositoryImpl.java index 3108be4e1..9cdac8a28 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeWritePlatformServiceJpaRepositoryImpl.java @@ -100,41 +100,6 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP } } - @Transactional - @Override - public Long interBranchMoneyTransfer(final BranchMoneyTransferCommand command) { - - context.authenticatedUser(); - - BranchMoneyTransferCommandValidator validator = new BranchMoneyTransferCommandValidator(command); - validator.validateInterBranchTransfer(); - - Office fromOffice = this.officeRepository.findOne(command.getFromOfficeId()); - if (fromOffice == null) { - throw new OfficeNotFoundException(command.getFromOfficeId()); - } - - Office toOffice = this.officeRepository.findOne(command.getToOfficeId()); - if (toOffice == null) { - throw new OfficeNotFoundException(command.getToOfficeId()); - } - - final String currencyCode = command.getCurrencyCode(); - ApplicationCurrency appCurrency = this.applicationCurrencyRepository.findOneByCode(currencyCode); - if (appCurrency == null) { - throw new CurrencyNotFoundException(currencyCode); - } - - MonetaryCurrency currency = new MonetaryCurrency(appCurrency.getCode(), appCurrency.getDecimalPlaces()); - Money amount = Money.of(currency, command.getTransactionAmountValue()); - - OfficeTransaction entity = OfficeTransaction.create(fromOffice, toOffice, command.getTransactionLocalDate(), amount); - - this.officeMonetaryTransferRepository.save(entity); - - return entity.getId(); - } - @Transactional @Override public Long externalBranchMoneyTransfer(BranchMoneyTransferCommand command) { @@ -144,8 +109,15 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP BranchMoneyTransferCommandValidator validator = new BranchMoneyTransferCommandValidator(command); validator.validateExternalBranchTransfer(); - Office fromOffice = this.officeRepository.findOne(command.getFromOfficeId()); - Office toOffice = this.officeRepository.findOne(command.getToOfficeId()); + Office fromOffice = null; + if (command.getFromOfficeId() != null) { + fromOffice = this.officeRepository.findOne(command.getFromOfficeId()); + } + Office toOffice = null; + if (command.getToOfficeId() != null) { + toOffice = this.officeRepository.findOne(command.getToOfficeId()); + } + if (fromOffice == null && toOffice == null) { throw new OfficeNotFoundException(command.getToOfficeId()); }