diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp index 1a5d4b3b1..73c73b90d 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/orghome.jsp @@ -133,9 +133,8 @@ removeErrors(placeholderDiv); var jsonErrors = JSON.parse(jqXHR.responseText); - console.log(jsonErrors); var valErrors = jsonErrors.errors; - console.log(valErrors); + var errorArray = new Array(); var arrayIndex = 0; $.each(valErrors, function() { @@ -152,7 +151,6 @@ argArray[argArrayIndex] = this.value; argArrayIndex++; }); - console.log(argArray); // hardcoded support for six arguments errorObj.message = jQuery.i18n.prop(this.userMessageGlobalisationCode, argArray[0], argArray[1], argArray[2], argArray[3], argArray[4], argArray[5]); errorObj.value = this.value; @@ -236,7 +234,6 @@ xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { - console.log(data); var formHtml = $(templateSelector).render(data); dialogDiv.append(formHtml); @@ -256,7 +253,6 @@ }); var newFormData = JSON.stringify($('#entityform').serializeObject()); - console.log(newFormData); var jqxhr = $.ajax({ url: postUrl, @@ -435,7 +431,6 @@ dataType: 'json', cache: false, beforeSend: function(xhr) { - console.log("base64: " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { diff --git a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/userhome.jsp b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/userhome.jsp index 234fd27b4..e75ace628 100644 --- a/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/userhome.jsp +++ b/mifosng-individual-lending-app/src/main/webapp/WEB-INF/views/admin/userhome.jsp @@ -191,11 +191,9 @@ $(document).ready(function() { dataType: 'json', cache: false, beforeSend: function(xhr) { - console.log("base64: " + base64); xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { - console.log(data); var formHtml = $(templateSelector).render(data); dialogDiv.append(formHtml); @@ -226,7 +224,6 @@ $(document).ready(function() { } var newFormData = JSON.stringify($('#entityform').serializeObject()); - console.log(newFormData); var jqxhr = $.ajax({ url: postUrl, @@ -303,7 +300,6 @@ $(document).ready(function() { xhr.setRequestHeader("Authorization", "Basic " + base64); }, success: function(data, textStatus, jqXHR) { - console.log(data); var tableHtml = $(templateSelector).render(data); $(displayAreaDivSelector).html(""); @@ -517,7 +513,7 @@ $(document).ready(function() { var saveSuccessFunction = function(data, textStatus, jqXHR) { $("#dialog-form").dialog("close"); - refreshUsersView(); + refreshRolesView(); } popupDialogWithFormView(getUrl, putUrl, 'PUT', "dialog.title.edit.details", templateSelector, width, height, saveSuccessFunction, true); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/AdditionalFieldsApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/AdditionalFieldsApiResource.java index 002525d42..2d2ccb694 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/AdditionalFieldsApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/AdditionalFieldsApiResource.java @@ -36,7 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/additionalfields") +@Path("/additionalfields") @Component @Scope("singleton") public class AdditionalFieldsApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/AuthenticationApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/AuthenticationApiResource.java index e8360659a..8c5a3819f 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/AuthenticationApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/AuthenticationApiResource.java @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component; import com.sun.jersey.core.util.Base64; -@Path("/v1/authentication") +@Path("/authentication") @Component @Scope("singleton") public class AuthenticationApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java index 5ed79abcf..a2a90e8dc 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ClientApiResource.java @@ -33,7 +33,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/clients") +@Path("/clients") @Component @Scope("singleton") public class ClientApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java index 6fade6f03..f346a3ba2 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ConfigurationApiResource.java @@ -19,7 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/configurations") +@Path("/configurations") @Component @Scope("singleton") public class ConfigurationApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java index b5e8e3a20..89f0a5621 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoanProductApiResource.java @@ -27,7 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/loanproducts") +@Path("/loanproducts") @Component @Scope("singleton") public class LoanProductApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java index 9d901c1db..92118ef3d 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/LoansApiResource.java @@ -40,7 +40,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/loans") +@Path("/loans") @Component @Scope("singleton") public class LoansApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java index b4569eed1..fc65c29a7 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/OfficeApiResource.java @@ -27,7 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/offices") +@Path("/offices") @Component @Scope("singleton") public class OfficeApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/PermissionApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/PermissionApiResource.java index b5cf362f4..c351c29b9 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/PermissionApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/PermissionApiResource.java @@ -17,7 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/permissions") +@Path("/permissions") @Component @Scope("singleton") public class PermissionApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java index 31273eaf6..ec34bef1b 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/ReportingApiResource.java @@ -25,7 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/reports") +@Path("/reports") @Component @Scope("singleton") public class ReportingApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/RoleApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/RoleApiResource.java index bf1c18a84..b3e96dea7 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/RoleApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/RoleApiResource.java @@ -27,7 +27,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/roles") +@Path("/roles") @Component @Scope("singleton") public class RoleApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/api/UserApiResource.java b/mifosng-provider/src/main/java/org/mifosng/platform/api/UserApiResource.java index d840562ea..083fc0ba4 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/api/UserApiResource.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/api/UserApiResource.java @@ -25,7 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; -@Path("/v1/users") +@Path("/users") @Component @Scope("singleton") public class UserApiResource { diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java index d476ced61..944dd7d05 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientReadPlatformServiceImpl.java @@ -19,6 +19,7 @@ import org.mifosng.data.NoteData; import org.mifosng.data.OfficeData; import org.mifosng.data.OfficeLookup; import org.mifosng.platform.exceptions.ClientNotFoundException; +import org.mifosng.platform.exceptions.NoteNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.organisation.domain.Organisation; import org.mifosng.platform.organisation.service.OfficeReadPlatformService; @@ -257,7 +258,7 @@ public class ClientReadPlatformServiceImpl implements ClientReadPlatformService new Object[] { currentUser.getOrganisation().getId(), clientId, noteId }); } catch (EmptyResultDataAccessException e) { - throw new ClientNotFoundException(clientId); + throw new NoteNotFoundException(clientId); } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java index 97ffc0f3f..e4ea833dd 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/client/service/ClientWritePlatformServiceJpaRepositoryImpl.java @@ -14,6 +14,7 @@ import org.mifosng.platform.client.domain.Note; import org.mifosng.platform.client.domain.NoteRepository; import org.mifosng.platform.exceptions.ClientNotFoundException; import org.mifosng.platform.exceptions.NoteNotFoundException; +import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.organisation.domain.Office; import org.mifosng.platform.organisation.domain.OfficeRepository; import org.mifosng.platform.security.PlatformSecurityContext; @@ -49,6 +50,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP validator.validateForCreate(); Office clientOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), command.getOfficeId())); + if (clientOffice == null) { + throw new OfficeNotFoundException(command.getOfficeId()); + } String firstname = command.getFirstname(); String lastname = command.getLastname(); @@ -74,6 +78,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP validator.validateForUpdate(); Office clientOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), command.getOfficeId())); + if (clientOffice == null) { + throw new OfficeNotFoundException(command.getOfficeId()); + } String firstname = command.getFirstname(); String lastname = command.getLastname(); @@ -83,6 +90,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP } Client clientForUpdate = this.clientRepository.findOne(clientsThatMatch(currentUser.getOrganisation(), command.getId())); + if (clientForUpdate == null) { + throw new ClientNotFoundException(command.getId()); + } clientForUpdate.update(clientOffice, firstname, lastname, command.getExternalId(), command.getJoiningDate()); this.clientRepository.save(clientForUpdate); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/CurrencyNotFoundException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/CurrencyNotFoundException.java new file mode 100644 index 000000000..ad84491f4 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/CurrencyNotFoundException.java @@ -0,0 +1,11 @@ +package org.mifosng.platform.exceptions; + +/** + * A {@link RuntimeException} thrown when loan resources are not found. + */ +public class CurrencyNotFoundException extends PlatformResourceNotFoundException { + + public CurrencyNotFoundException(final String currencyCode) { + super("error.msg.currency.currencyCode.invalid", "Currency with identifier " + currencyCode + " does not exist", currencyCode); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanNotFoundException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanNotFoundException.java new file mode 100644 index 000000000..b440778ff --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanNotFoundException.java @@ -0,0 +1,11 @@ +package org.mifosng.platform.exceptions; + +/** + * A {@link RuntimeException} thrown when loan resources are not found. + */ +public class LoanNotFoundException extends PlatformResourceNotFoundException { + + public LoanNotFoundException(Long id) { + super("error.msg.loan.id.invalid", "Loan with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanProductNotFoundException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanProductNotFoundException.java new file mode 100644 index 000000000..dd772a03a --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanProductNotFoundException.java @@ -0,0 +1,11 @@ +package org.mifosng.platform.exceptions; + +/** + * A {@link RuntimeException} thrown when loan product resources are not found. + */ +public class LoanProductNotFoundException extends PlatformResourceNotFoundException { + + public LoanProductNotFoundException(Long id) { + super("error.msg.loanproduct.id.invalid", "Loan product with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanTransactionNotFoundException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanTransactionNotFoundException.java new file mode 100644 index 000000000..ae168eea3 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/LoanTransactionNotFoundException.java @@ -0,0 +1,11 @@ +package org.mifosng.platform.exceptions; + +/** + * A {@link RuntimeException} thrown when loan resources are not found. + */ +public class LoanTransactionNotFoundException extends PlatformResourceNotFoundException { + + public LoanTransactionNotFoundException(Long id) { + super("error.msg.loan.id.invalid", "Loan with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/OfficeNotFoundException.java b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/OfficeNotFoundException.java new file mode 100644 index 000000000..c681397e1 --- /dev/null +++ b/mifosng-provider/src/main/java/org/mifosng/platform/exceptions/OfficeNotFoundException.java @@ -0,0 +1,11 @@ +package org.mifosng.platform.exceptions; + +/** + * A {@link RuntimeException} thrown when office resources are not found. + */ +public class OfficeNotFoundException extends PlatformResourceNotFoundException { + + public OfficeNotFoundException(Long id) { + super("error.msg.office.id.invalid", "Office with identifier " + id + " does not exist", id); + } +} \ No newline at end of file diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java index d24d60bd7..3234a80bc 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/CalculationPlatformServiceImpl.java @@ -11,6 +11,8 @@ import org.mifosng.data.command.CalculateLoanScheduleCommand; import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.MonetaryCurrency; +import org.mifosng.platform.exceptions.CurrencyNotFoundException; +import org.mifosng.platform.exceptions.LoanNotFoundException; import org.mifosng.platform.loan.domain.AmortizationMethod; import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod; import org.mifosng.platform.loan.domain.InterestMethod; @@ -87,12 +89,18 @@ public class CalculationPlatformServiceImpl implements public LoanPayoffReadModel calculatePayoffOn(final Long loanId, final LocalDate payoffDate) { final Loan loan = this.loanRepository.findOne(loanId); + if (loan == null) { + throw new LoanNotFoundException(loanId); + } final LoanPayoffSummary payoffSummary = loan.getPayoffSummaryOn(payoffDate); final String currencyCode = payoffSummary.getTotalPaidToDate().getCurrencyCode(); ApplicationCurrency applicationCurrency = this.applicationCurrencyRepository.findOneByCode(currencyCode); + if (applicationCurrency == null) { + throw new CurrencyNotFoundException(currencyCode); + } final int currencyDigitsAfterDecimal = payoffSummary.getTotalPaidToDate().getCurrencyDigitsAfterDecimal(); CurrencyData currency = new CurrencyData(currencyCode, applicationCurrency.getName(), currencyDigitsAfterDecimal, applicationCurrency.getDisplaySymbol(), applicationCurrency.getNameCode()); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java index a992c3615..6ccd8d4f5 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loan/service/LoanReadPlatformServiceImpl.java @@ -19,6 +19,10 @@ import org.mifosng.platform.client.service.ClientReadPlatformService; import org.mifosng.platform.currency.domain.ApplicationCurrency; import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository; import org.mifosng.platform.currency.domain.Money; +import org.mifosng.platform.exceptions.CurrencyNotFoundException; +import org.mifosng.platform.exceptions.LoanNotFoundException; +import org.mifosng.platform.exceptions.LoanProductNotFoundException; +import org.mifosng.platform.exceptions.LoanTransactionNotFoundException; import org.mifosng.platform.loan.domain.Loan; import org.mifosng.platform.loan.domain.LoanRepository; import org.mifosng.platform.loan.domain.LoanTransaction; @@ -61,12 +65,16 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { // need of loan information. AppUser currentUser = context.authenticatedUser(); - Loan loan = this.loanRepository.findOne(loansThatMatch( - currentUser.getOrganisation(), loanId)); + Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); + if (loan == null) { + throw new LoanNotFoundException(loanId); + } - ApplicationCurrency currency = this.applicationCurrencyRepository - .findOneByCode(loan.getLoanRepaymentScheduleDetail() - .getPrincipal().getCurrencyCode()); + final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); + ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); + if (currency == null) { + throw new CurrencyNotFoundException(currencyCode); + } CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(), @@ -177,13 +185,18 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { if (loanProducts.size() == 1) { Long allowedProductId = workflowData.getAllowedProducts().get(0).getId(); LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(allowedProductId); + if (selectedProduct == null) { + throw new LoanProductNotFoundException(allowedProductId); + } workflowData.setProductId(selectedProduct.getId()); workflowData.setProductName(selectedProduct.getName()); workflowData.setSelectedProduct(selectedProduct); } else { LoanProductData selectedProduct = findLoanProductById(loanProducts, productId); - + if (selectedProduct == null) { + throw new LoanProductNotFoundException(productId); + } workflowData.setProductId(selectedProduct.getId()); workflowData.setProductName(selectedProduct.getName()); workflowData.setSelectedProduct(selectedProduct); @@ -219,20 +232,23 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { // TODO - OPTIMIZE - write simple sql query to fetch back date of // possible next transaction date. Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); + if (loan == null) { + throw new LoanNotFoundException(loanId); + } - ApplicationCurrency currency = this.applicationCurrencyRepository - .findOneByCode(loan.getLoanRepaymentScheduleDetail() - .getPrincipal().getCurrencyCode()); + final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); + ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); + if (currency == null) { + throw new CurrencyNotFoundException(currencyCode); + } CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(), currency.getDisplaySymbol(), currency.getNameCode()); - LocalDate earliestUnpaidInstallmentDate = loan - .possibleNextRepaymentDate(); + LocalDate earliestUnpaidInstallmentDate = loan.possibleNextRepaymentDate(); Money possibleNextRepaymentAmount = loan.possibleNextRepaymentAmount(); - MoneyData possibleNextRepayment = MoneyData.of(currencyData, - possibleNextRepaymentAmount.getAmount()); + MoneyData possibleNextRepayment = MoneyData.of(currencyData, possibleNextRepaymentAmount.getAmount()); LoanRepaymentData newRepaymentDetails = new LoanRepaymentData(); newRepaymentDetails.setDate(earliestUnpaidInstallmentDate); @@ -250,10 +266,15 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { // possible next transaction date. Loan loan = this.loanRepository.findOne(loansThatMatch( currentUser.getOrganisation(), loanId)); + if (loan == null) { + throw new LoanNotFoundException(loanId); + } - ApplicationCurrency currency = this.applicationCurrencyRepository - .findOneByCode(loan.getLoanRepaymentScheduleDetail() - .getPrincipal().getCurrencyCode()); + final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); + ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); + if (currency == null) { + throw new CurrencyNotFoundException(currencyCode); + } CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(), @@ -271,21 +292,25 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { } @Override - public LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, - Long repaymentId) { + public LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long transactionId) { AppUser currentUser = context.authenticatedUser(); - LoanTransaction transaction = this.loanTransactionRepository - .findOne(loanTransactionsThatMatch( - currentUser.getOrganisation(), repaymentId)); + Loan loan = this.loanRepository.findOne(loansThatMatch(currentUser.getOrganisation(), loanId)); + if (loan == null) { + throw new LoanNotFoundException(loanId); + } - Loan loan = this.loanRepository.findOne(loansThatMatch( - currentUser.getOrganisation(), loanId)); + final String currencyCode = loan.getLoanRepaymentScheduleDetail().getPrincipal().getCurrencyCode(); + ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode); + if (currency == null) { + throw new CurrencyNotFoundException(currencyCode); + } - ApplicationCurrency currency = this.applicationCurrencyRepository - .findOneByCode(loan.getLoanRepaymentScheduleDetail() - .getPrincipal().getCurrencyCode()); + LoanTransaction transaction = this.loanTransactionRepository.findOne(loanTransactionsThatMatch(currentUser.getOrganisation(), transactionId)); + if (transaction == null) { + throw new LoanTransactionNotFoundException(transactionId); + } CurrencyData currencyData = new CurrencyData(currency.getCode(), currency.getName(), currency.getDecimalPlaces(), @@ -294,7 +319,7 @@ public class LoanReadPlatformServiceImpl implements LoanReadPlatformService { LocalDate date = transaction.getTransactionDate(); LoanRepaymentData loanRepaymentData = new LoanRepaymentData(); - loanRepaymentData.setId(repaymentId); + loanRepaymentData.setId(transactionId); loanRepaymentData.setTotal(total); loanRepaymentData.setDate(date); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java index f81767891..02babda0d 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductReadPlatformServiceImpl.java @@ -14,7 +14,7 @@ import org.mifosng.data.EnumOptionData; import org.mifosng.data.LoanProductData; import org.mifosng.data.MoneyData; import org.mifosng.platform.currency.service.CurrencyReadPlatformService; -import org.mifosng.platform.exceptions.PlatformResourceNotFoundException; +import org.mifosng.platform.exceptions.LoanProductNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.security.PlatformSecurityContext; import org.mifosng.platform.user.domain.AppUser; @@ -57,7 +57,7 @@ public class LoanProductReadPlatformServiceImpl implements LoanProductReadPlatfo return productData; } catch (EmptyResultDataAccessException e) { - throw new PlatformResourceNotFoundException("error.msg.loanproduct.id.invalid", "Loan product with identifier {0} does not exist.", loanProductId); + throw new LoanProductNotFoundException(loanProductId); } } diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java index 44849bca3..16a200952 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/loanproduct/service/LoanProductWritePlatformServiceJpaRepositoryImpl.java @@ -7,7 +7,7 @@ import java.math.BigDecimal; import org.mifosng.data.EntityIdentifier; import org.mifosng.data.command.LoanProductCommand; import org.mifosng.platform.currency.domain.MonetaryCurrency; -import org.mifosng.platform.exceptions.PlatformResourceNotFoundException; +import org.mifosng.platform.exceptions.LoanProductNotFoundException; import org.mifosng.platform.loan.domain.AmortizationMethod; import org.mifosng.platform.loan.domain.InterestCalculationPeriodMethod; import org.mifosng.platform.loan.domain.InterestMethod; @@ -81,7 +81,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro LoanProduct product = this.loanProductRepository.findOne(productThatMatches(currentUser.getOrganisation(), command.getId())); if (product == null) { - throw new PlatformResourceNotFoundException("error.msg.loanproduct.id.invalid", "Loan product with identifier {0} does not exist.", command.getId()); + throw new LoanProductNotFoundException(command.getId()); } product.update(command); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java index 7eefc06fd..3814127d8 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/organisation/service/OfficeReadPlatformServiceImpl.java @@ -11,7 +11,7 @@ import javax.sql.DataSource; import org.joda.time.LocalDate; import org.mifosng.data.OfficeData; import org.mifosng.data.OfficeLookup; -import org.mifosng.platform.exceptions.PlatformResourceNotFoundException; +import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.security.PlatformSecurityContext; import org.mifosng.platform.user.domain.AppUser; @@ -122,9 +122,7 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService return selectedOffice; } catch (EmptyResultDataAccessException e) { - throw new PlatformResourceNotFoundException( - "error.msg.office.id.invalid", - "Office with identifier {0} does not exist.", officeId); + throw new OfficeNotFoundException(officeId); } } 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 bec2b2555..b25a20aca 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 @@ -4,6 +4,7 @@ import static org.mifosng.platform.Specifications.officesThatMatch; import org.mifosng.data.command.OfficeCommand; import org.mifosng.platform.exceptions.NoAuthorizationException; +import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException; import org.mifosng.platform.organisation.domain.Office; import org.mifosng.platform.organisation.domain.OfficeRepository; @@ -42,6 +43,9 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP validator.validateForCreate(); Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId()); + if (parent == null) { + throw new OfficeNotFoundException(command.getParentId()); + } Office office = Office.createNew(currentUser.getOrganisation(), parent, command.getName(), command.getOpeningDate(), command.getExternalId()); @@ -70,11 +74,17 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP validator.validateForUpdate(); Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getId()); + if (office == null) { + throw new OfficeNotFoundException(command.getId()); + } office.update(command); if (!command.isRootOffice() && command.getParentId() != null) { Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId()); + if (parent == null) { + throw new OfficeNotFoundException(command.getParentId()); + } office.update(parent); } @@ -109,6 +119,9 @@ public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWriteP private Office validateUserPriviledgeOnOfficeAndRetrieve(AppUser currentUser, Long officeId) { Office userOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), currentUser.getOffice().getId())); + if (userOffice == null) { + throw new OfficeNotFoundException(currentUser.getOffice().getId()); + } if (userOffice.doesNotHaveAnOfficeInHierarchyWithId(officeId)) { throw new NoAuthorizationException("User does not have sufficient priviledges to act on the provided office."); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserReadPlatformServiceImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserReadPlatformServiceImpl.java index f4c7c4633..4be4db014 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserReadPlatformServiceImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserReadPlatformServiceImpl.java @@ -15,7 +15,7 @@ import org.mifosng.data.AppUserData; import org.mifosng.data.OfficeData; import org.mifosng.data.OfficeLookup; import org.mifosng.data.RoleData; -import org.mifosng.platform.exceptions.RoleNotFoundException; +import org.mifosng.platform.exceptions.UserNotFoundException; import org.mifosng.platform.infrastructure.JdbcSupport; import org.mifosng.platform.organisation.service.OfficeReadPlatformService; import org.mifosng.platform.security.PlatformSecurityContext; @@ -102,7 +102,7 @@ public class AppUserReadPlatformServiceImpl implements AppUserReadPlatformServic AppUser user = this.appUserRepository.findOne(usersThatMatch(currentUser.getOrganisation(), userId)); if (user == null) { - throw new RoleNotFoundException(userId); + throw new UserNotFoundException(userId); } List userRoleData = new ArrayList(); diff --git a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java index e5de4d999..7a81ffe9c 100644 --- a/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java +++ b/mifosng-provider/src/main/java/org/mifosng/platform/user/service/AppUserWritePlatformServiceJpaRepositoryImpl.java @@ -10,9 +10,11 @@ import java.util.Set; import org.apache.commons.lang.StringUtils; import org.mifosng.data.ApiParameterError; import org.mifosng.data.command.UserCommand; +import org.mifosng.platform.exceptions.OfficeNotFoundException; import org.mifosng.platform.exceptions.PlatformApiDataValidationException; import org.mifosng.platform.exceptions.PlatformDataIntegrityException; -import org.mifosng.platform.exceptions.PlatformResourceNotFoundException; +import org.mifosng.platform.exceptions.RoleNotFoundException; +import org.mifosng.platform.exceptions.UserNotFoundException; import org.mifosng.platform.infrastructure.BasicPasswordEncodablePlatformUser; import org.mifosng.platform.infrastructure.PlatformEmailSendException; import org.mifosng.platform.infrastructure.PlatformPasswordEncoder; @@ -69,6 +71,9 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit Set allRoles = assembleSetOfRoles(command.getRoles()); Office office = this.officeRepository.findOne(command.getOfficeId()); + if (office == null) { + throw new OfficeNotFoundException(command.getOfficeId()); + } String password = command.getPassword(); if (StringUtils.isBlank(password)) { @@ -111,13 +116,13 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit if (command.getOfficeId() != null) { office = this.officeRepository.findOne(command.getOfficeId()); if (office == null) { - throw new PlatformResourceNotFoundException("error.msg.office.id.invalid", "Office with identifier {0} does not exist.", command.getOfficeId()); + throw new OfficeNotFoundException(command.getOfficeId()); } } AppUser userToUpdate = this.appUserRepository.findOne(usersThatMatch(currentUser.getOrganisation(), command.getId())); if (userToUpdate == null) { - throw new PlatformResourceNotFoundException("error.msg.user.id.invalid", "User with identifier {0} does not exist.", command.getId()); + throw new UserNotFoundException(command.getId()); } userToUpdate.update(allRoles, office, command.getUsername(), command.getFirstname(), command.getLastname(), command.getEmail()); @@ -145,7 +150,11 @@ public class AppUserWritePlatformServiceJpaRepositoryImpl implements AppUserWrit Set allRoles = new HashSet(); if (!ObjectUtils.isEmpty(rolesArray)) { for (String roleId : rolesArray) { - Role role = this.roleRepository.findOne(Long.valueOf(roleId)); + Long id = Long.valueOf(roleId); + Role role = this.roleRepository.findOne(id); + if (role == null) { + throw new RoleNotFoundException(id); + } allRoles.add(role); } } diff --git a/mifosng-provider/src/main/webapp/WEB-INF/web.xml b/mifosng-provider/src/main/webapp/WEB-INF/web.xml index ffb87ee3d..5c5caa845 100644 --- a/mifosng-provider/src/main/webapp/WEB-INF/web.xml +++ b/mifosng-provider/src/main/webapp/WEB-INF/web.xml @@ -75,7 +75,7 @@ jersey-serlvet - /api/* + /api/v1/*