handle resource not found possibilities. move version information to web.xml rather than each resource.

This commit is contained in:
Keith Woodlock
2012-05-28 21:02:29 +01:00
parent 1cf29aaead
commit 682b11f78e
29 changed files with 175 additions and 65 deletions
@@ -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) {
@@ -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);
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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 {
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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());
@@ -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);
@@ -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);
}
}
@@ -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);
@@ -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);
}
}
@@ -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.");
@@ -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<RoleData> userRoleData = new ArrayList<RoleData>();
@@ -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<Role> 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<Role> allRoles = new HashSet<Role>();
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);
}
}
@@ -75,7 +75,7 @@
<servlet-mapping>
<servlet-name>jersey-serlvet</servlet-name>
<url-pattern>/api/*</url-pattern>
<url-pattern>/api/v1/*</url-pattern>
</servlet-mapping>
<servlet>