finish off integration of organisation admin functions in UI with backend services through cross origin request from jQuery.

This commit is contained in:
Keith Woodlock
2012-05-11 14:24:16 +01:00
parent 525831db04
commit f82c87de78
34 changed files with 544 additions and 1946 deletions
@@ -10,16 +10,13 @@ import org.mifosng.data.ClientDataWithAccountsData;
import org.mifosng.data.CurrencyData;
import org.mifosng.data.EnumOptionReadModel;
import org.mifosng.data.LoanAccountData;
import org.mifosng.data.LoanProductData;
import org.mifosng.data.LoanRepaymentData;
import org.mifosng.data.NewLoanWorkflowStepOneData;
import org.mifosng.data.NoteData;
import org.mifosng.data.OfficeData;
import org.mifosng.data.OrganisationReadModel;
import org.mifosng.data.PermissionData;
import org.mifosng.data.RoleData;
import org.mifosng.data.reports.GenericResultset;
import org.springframework.security.access.prepost.PreAuthorize;
public interface ReadPlatformService {
@@ -27,8 +24,6 @@ public interface ReadPlatformService {
Collection<ClientData> retrieveAllIndividualClients();
Collection<OfficeData> retrieveAllOffices();
ClientData retrieveIndividualClient(Long clientId);
ClientDataWithAccountsData retrieveClientAccountDetails(Long clientId);
@@ -43,28 +38,10 @@ public interface ReadPlatformService {
LoanRepaymentData retrieveLoanRepaymentDetails(Long loanId, Long repaymentId);
Collection<LoanProductData> retrieveAllLoanProducts();
List<CurrencyData> retrieveAllowedCurrencies();
List<CurrencyData> retrieveAllPlatformCurrencies();
List<EnumOptionReadModel> retrieveLoanAmortizationMethodOptions();
List<EnumOptionReadModel> retrieveLoanInterestMethodOptions();
List<EnumOptionReadModel> retrieveLoanInterestRateCalculatedInPeriodOptions();
List<EnumOptionReadModel> retrieveRepaymentFrequencyOptions();
List<EnumOptionReadModel> retrieveInterestFrequencyOptions();
LoanProductData retrieveLoanProduct(Long productId);
LoanProductData retrieveNewLoanProductDetails();
OfficeData retrieveOffice(Long officeId);
Collection<AppUserData> retrieveAllUsers();
AppUserData retrieveNewUserDetails();
@@ -5,14 +5,12 @@ import static org.mifosng.platform.Specifications.loanTransactionsThatMatch;
import static org.mifosng.platform.Specifications.loansThatMatch;
import static org.mifosng.platform.Specifications.usersThatMatch;
import java.math.BigDecimal;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -53,12 +51,11 @@ import org.mifosng.platform.currency.domain.ApplicationCurrencyRepository;
import org.mifosng.platform.currency.domain.Money;
import org.mifosng.platform.exceptions.PlatformResourceNotFoundException;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.mifosng.platform.loan.domain.AmortizationMethod;
import org.mifosng.platform.loan.domain.Loan;
import org.mifosng.platform.loan.domain.LoanRepository;
import org.mifosng.platform.loan.domain.LoanTransaction;
import org.mifosng.platform.loan.domain.LoanTransactionRepository;
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
import org.mifosng.platform.loanproduct.service.LoanProductReadPlatformService;
import org.mifosng.platform.organisation.domain.Organisation;
import org.mifosng.platform.user.domain.AppUser;
import org.mifosng.platform.user.domain.AppUserRepository;
@@ -91,14 +88,18 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
private final AppUserRepository appUserRepository;
private final RoleRepository roleRepository;
private final LoanProductReadPlatformService loanProductReadPlatformService;
@Autowired
public ReadPlatformServiceImpl(final DataSource dataSource,
public ReadPlatformServiceImpl(final LoanProductReadPlatformService loanProductReadPlatformService,
final DataSource dataSource,
final ClientRepository clientRepository,
final LoanRepository loanRepository,
final LoanTransactionRepository loanTransactionRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository,
final AppUserRepository appUserRepository,
final RoleRepository roleRepository) {
this.loanProductReadPlatformService = loanProductReadPlatformService;
this.loanTransactionRepository = loanTransactionRepository;
this.applicationCurrencyRepository = applicationCurrencyRepository;
this.appUserRepository = appUserRepository;
@@ -360,47 +361,6 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
}
}
@Override
public Collection<OfficeData> retrieveAllOffices() {
return retrieveOffices();
}
@Override
public OfficeData retrieveOffice(final Long officeId) {
try {
AppUser currentUser = extractAuthenticatedUser();
OfficeMapper rm = new OfficeMapper();
String sql = "select " + rm.officeSchema()
+ " where o.org_id = ? and o.id = ?";
OfficeData selectedOffice = this.jdbcTemplate.queryForObject(sql,
rm, new Object[] { currentUser.getOrganisation().getId(),
officeId });
List<OfficeData> allowedParents = new ArrayList<OfficeData>();
if (StringUtils.isNotBlank(selectedOffice.getParentName())) {
Collection<OfficeData> allOffices = retrieveAllOffices();
for (OfficeData office : allOffices) {
if (!office.getId().equals(selectedOffice.getId())) {
allowedParents.add(office);
}
}
}
selectedOffice.setAllowedParents(allowedParents);
return selectedOffice;
} catch (EmptyResultDataAccessException e) {
throw new PlatformResourceNotFoundException("error.msg.office.id.invalid", "Office with identifier {0} does not exist", officeId);
}
}
@Override
public ClientData retrieveIndividualClient(final Long clientId) {
@@ -571,12 +531,12 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
workflowData.setOrganisationName(currentUser.getOrganisation()
.getName());
Collection<LoanProductData> loanProducts = retrieveAllLoanProducts();
Collection<LoanProductData> loanProducts = this.loanProductReadPlatformService.retrieveAllLoanProducts();
workflowData.setAllowedProducts(new ArrayList<LoanProductData>(
loanProducts));
if (loanProducts.size() == 1) {
LoanProductData selectedProduct = retrieveLoanProduct(workflowData.getAllowedProducts().get(0).getId());
LoanProductData selectedProduct = this.loanProductReadPlatformService.retrieveLoanProduct(workflowData.getAllowedProducts().get(0).getId());
workflowData.setProductId(selectedProduct.getId());
workflowData.setProductName(selectedProduct.getName());
@@ -597,10 +557,10 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
}
private LoanProductData findLoanProductById(Collection<LoanProductData> loanProducts, Long productId) {
LoanProductData match = retrieveNewLoanProductDetails();
LoanProductData match = this.loanProductReadPlatformService.retrieveNewLoanProductDetails();
for (LoanProductData loanProductData : loanProducts) {
if (loanProductData.getId().equals(productId)) {
match = retrieveLoanProduct(loanProductData.getId());
match = this.loanProductReadPlatformService.retrieveLoanProduct(loanProductData.getId());
break;
}
}
@@ -707,165 +667,6 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
tolerance, loanData, waiveAllowed, interestRebateOwed);
}
@Override
public Collection<LoanProductData> retrieveAllLoanProducts() {
AppUser currentUser = extractAuthenticatedUser();
List<CurrencyData> allowedCurrencies = retrieveAllowedCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
String sql = "select " + rm.loanProductSchema()
+ " where lp.org_id = ?";
return this.jdbcTemplate.query(sql, rm, new Object[] { currentUser
.getOrganisation().getId() });
}
protected static final class LoanProductMapper implements
RowMapper<LoanProductData> {
private final List<CurrencyData> allowedCurrencies;
public LoanProductMapper(List<CurrencyData> allowedCurrencies) {
this.allowedCurrencies = allowedCurrencies;
}
public String loanProductSchema() {
return "lp.id as id, lp.name as name, lp.description as description, lp.flexible_repayment_schedule as isFlexible, lp.interest_rebate as isInterestRebateAllowed, "
+ "lp.principal_amount as principal, lp.currency_code as currencyCode, lp.currency_digits as currencyDigits, "
+ "lp.nominal_interest_rate_per_period as interestRatePerPeriod, lp.interest_period_frequency_enum as interestRatePerPeriodFreq, "
+ "lp.annual_nominal_interest_rate as annualInterestRate, lp.interest_method_enum as interestMethod, lp.interest_calculated_in_period_enum as interestCalculationInPeriodMethod,"
+ "lp.repay_every as repaidEvery, lp.repayment_period_frequency_enum as repaymentPeriodFrequency, lp.number_of_repayments as numberOfRepayments, "
+ "lp.amortization_method_enum as amortizationMethod, lp.arrearstolerance_amount as tolerance, "
+ "lp.created_date as createdon, lp.lastmodified_date as modifiedon "
+ " from portfolio_product_loan lp";
}
@Override
public LoanProductData mapRow(final ResultSet rs, final int rowNum)
throws SQLException {
Long id = rs.getLong("id");
String name = rs.getString("name");
String description = rs.getString("description");
boolean isFlexible = rs.getBoolean("isFlexible");
boolean isInterestRebateAllowed = rs
.getBoolean("isInterestRebateAllowed");
String currencyCode = rs.getString("currencyCode");
int currencyDigits = rs.getInt("currencyDigits");
CurrencyData currencyData = findCurrencyByCode(currencyCode, allowedCurrencies);
currencyData.setDecimalPlaces(currencyDigits);
BigDecimal principal = rs.getBigDecimal("principal");
BigDecimal tolerance = rs.getBigDecimal("tolerance");
MoneyData principalMoney = MoneyData.of(currencyData, principal);
MoneyData toleranceMoney = MoneyData.of(currencyData, tolerance);
BigDecimal interestRatePerPeriod = rs
.getBigDecimal("interestRatePerPeriod");
int interestRatePeriod = rs.getInt("interestRatePerPeriodFreq");
BigDecimal annualInterestRate = rs
.getBigDecimal("annualInterestRate");
int interestMethod = rs.getInt("interestMethod");
int interestCalculationInPeriodMethod = rs.getInt("interestCalculationInPeriodMethod");
int repaidEvery = rs.getInt("repaidEvery");
int repaymentFrequency = rs.getInt("repaymentPeriodFrequency");
int numberOfRepayments = rs.getInt("numberOfRepayments");
int amortizationMethod = rs.getInt("amortizationMethod");
DateTime createdOn = new DateTime(rs.getDate("createdOn"));
DateTime lastModifedOn = new DateTime(rs.getDate("modifiedon"));
return new LoanProductData(id, name, description, isFlexible,
isInterestRebateAllowed, principalMoney,
interestRatePerPeriod, interestRatePeriod,
annualInterestRate, interestMethod, interestCalculationInPeriodMethod,
repaidEvery,
repaymentFrequency, numberOfRepayments, amortizationMethod,
toleranceMoney, createdOn, lastModifedOn);
}
private CurrencyData findCurrencyByCode(String currencyCode, List<CurrencyData> allowedCurrencies) {
CurrencyData match = null;
for (CurrencyData currencyData : allowedCurrencies) {
if (currencyData.getCode().equalsIgnoreCase(currencyCode)) {
match = currencyData;
break;
}
}
return match;
}
}
@Override
public LoanProductData retrieveLoanProduct(final Long loanProductId) {
// TODO - switch back to retrieve all allowed organisation currencies
List<CurrencyData> allowedCurrencies = retrieveAllPlatformCurrencies();
LoanProductMapper rm = new LoanProductMapper(allowedCurrencies);
String sql = "select " + rm.loanProductSchema() + " where lp.id = ?";
LoanProductData productData = this.jdbcTemplate.queryForObject(sql, rm,
new Object[] { loanProductId });
populateProductDataWithDropdownOptions(productData);
return productData;
}
private void populateProductDataWithDropdownOptions(
LoanProductData productData) {
List<CurrencyData> possibleCurrencies = retrieveAllowedCurrencies();
List<EnumOptionReadModel> possibleAmortizationOptions = retrieveLoanAmortizationMethodOptions();
List<EnumOptionReadModel> possibleInterestOptions = retrieveLoanInterestMethodOptions();
List<EnumOptionReadModel> possibleInterestRateCalculatedInPeriodOptions = retrieveLoanInterestRateCalculatedInPeriodOptions();
List<EnumOptionReadModel> repaymentFrequencyOptions = retrieveRepaymentFrequencyOptions();
List<EnumOptionReadModel> interestFrequencyOptions = retrieveInterestFrequencyOptions();
productData.setPossibleCurrencies(possibleCurrencies);
productData.setPossibleAmortizationOptions(possibleAmortizationOptions);
productData.setPossibleInterestOptions(possibleInterestOptions);
productData.setPossibleInterestRateCalculatedInPeriodOptions(possibleInterestRateCalculatedInPeriodOptions);
productData.setRepaymentFrequencyOptions(repaymentFrequencyOptions);
productData.setInterestFrequencyOptions(interestFrequencyOptions);
}
@Override
public LoanProductData retrieveNewLoanProductDetails() {
LoanProductData productData = new LoanProductData();
populateProductDataWithDropdownOptions(productData);
if (productData.getPossibleCurrencies().size() >= 1) {
CurrencyData currency = productData.getPossibleCurrencies().get(0);
MoneyData zero = MoneyData.zero(currency);
productData.setPrincipalMoney(zero);
productData.setInArrearsTolerance(zero);
}
productData.setAmortizationMethod(Integer.valueOf(1));
productData.setInterestMethod(Integer.valueOf(0));
productData.setRepaymentPeriodFrequency(2);
productData.setInterestRatePeriod(2);
productData.setInterestRateCalculatedInPeriod(1);
productData.setRepaidEvery(1);
productData.setNumberOfRepayments(0);
return productData;
}
@Override
public List<CurrencyData> retrieveAllowedCurrencies() {
@@ -906,71 +707,7 @@ public class ReadPlatformServiceImpl implements ReadPlatformService {
nameCode);
}
}
@Override
public List<EnumOptionReadModel> retrieveLoanAmortizationMethodOptions() {
EnumOptionReadModel equalInstallments = new EnumOptionReadModel(
"Equal installments", AmortizationMethod.EQUAL_INSTALLMENTS
.getValue().longValue());
EnumOptionReadModel equalPrinciplePayments = new EnumOptionReadModel(
"Equal principle payments", AmortizationMethod.EQUAL_PRINCIPAL
.getValue().longValue());
List<EnumOptionReadModel> allowedAmortizationMethods = Arrays.asList(
equalInstallments, equalPrinciplePayments);
return allowedAmortizationMethods;
}
@Override
public List<EnumOptionReadModel> retrieveLoanInterestMethodOptions() {
EnumOptionReadModel interestRateCalculationMethod2 = new EnumOptionReadModel(
"Declining Balance", Long.valueOf(0));
EnumOptionReadModel interestRateCalculationMethod1 = new EnumOptionReadModel(
"Flat", Long.valueOf(1));
List<EnumOptionReadModel> allowedRepaymentScheduleCalculationMethods = Arrays
.asList(interestRateCalculationMethod2,
interestRateCalculationMethod1);
return allowedRepaymentScheduleCalculationMethods;
}
@Override
public List<EnumOptionReadModel> retrieveLoanInterestRateCalculatedInPeriodOptions() {
EnumOptionReadModel option1 = new EnumOptionReadModel("Daily", Long.valueOf(0));
EnumOptionReadModel option2 = new EnumOptionReadModel("Same as repayment period", Long.valueOf(1));
List<EnumOptionReadModel> allowedOptions = Arrays.asList(option1,option2);
return allowedOptions;
}
@Override
public List<EnumOptionReadModel> retrieveRepaymentFrequencyOptions() {
EnumOptionReadModel frequency1 = new EnumOptionReadModel("Days",
Long.valueOf(0));
EnumOptionReadModel frequency2 = new EnumOptionReadModel("Weeks",
Long.valueOf(1));
EnumOptionReadModel frequency3 = new EnumOptionReadModel("Months",
Long.valueOf(2));
List<EnumOptionReadModel> repaymentFrequencyOptions = Arrays.asList(
frequency1, frequency2, frequency3);
return repaymentFrequencyOptions;
}
@Override
public List<EnumOptionReadModel> retrieveInterestFrequencyOptions() {
// support for monthly and annual percentage rate (MPR) and (APR)
EnumOptionReadModel perMonth = new EnumOptionReadModel("Per month",
PeriodFrequencyType.MONTHS.getValue().longValue());
EnumOptionReadModel perYear = new EnumOptionReadModel("Per year",
PeriodFrequencyType.YEARS.getValue().longValue());
List<EnumOptionReadModel> repaymentFrequencyOptions = Arrays.asList(perMonth, perYear);
return repaymentFrequencyOptions;
}
@Override
public Collection<AppUserData> retrieveAllUsers() {
@@ -4,17 +4,14 @@ import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.command.AdjustLoanTransactionCommand;
import org.mifosng.data.command.ChangePasswordCommand;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.data.command.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.data.command.OfficeCommand;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.data.command.SignupCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoLoanApprovalCommand;
import org.mifosng.data.command.UndoLoanDisbursalCommand;
import org.mifosng.data.command.UpdateOrganisationCurrencyCommand;
import org.mifosng.data.command.UpdateUsernamePasswordCommand;
import org.mifosng.data.command.UserCommand;
import org.mifosng.platform.exceptions.InvalidSignupException;
@@ -22,10 +19,6 @@ import org.springframework.security.access.prepost.PreAuthorize;
public interface WritePlatformService {
Long createOffice(OfficeCommand command);
Long updateOffice(OfficeCommand command);
Long createUser(UserCommand command);
Long updateUser(UserCommand command);
@@ -50,12 +43,6 @@ public interface WritePlatformService {
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_ENROLL_NEW_CLIENT_ROLE')")
Long enrollClient(EnrollClientCommand command);
void updateOrganisationCurrencies(UpdateOrganisationCurrencyCommand command);
EntityIdentifier createLoanProduct(LoanProductCommand command);
EntityIdentifier updateLoanProduct(LoanProductCommand command);
@PreAuthorize(value = "hasAnyRole('PORTFOLIO_MANAGEMENT_SUPER_USER_ROLE', 'CAN_DELETE_LOAN_THAT_IS_SUBMITTED_AND_NOT_APPROVED')")
EntityIdentifier deleteLoan(Long loanId);
@@ -2,7 +2,6 @@ package org.mifosng.platform;
import static org.mifosng.platform.Specifications.loansThatMatch;
import static org.mifosng.platform.Specifications.officesThatMatch;
import static org.mifosng.platform.Specifications.productThatMatches;
import static org.mifosng.platform.Specifications.rolesThatMatch;
import static org.mifosng.platform.Specifications.usersThatMatch;
@@ -25,32 +24,26 @@ import org.mifosng.data.command.AdjustLoanTransactionCommand;
import org.mifosng.data.command.CalculateLoanScheduleCommand;
import org.mifosng.data.command.ChangePasswordCommand;
import org.mifosng.data.command.EnrollClientCommand;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.data.command.LoanStateTransitionCommand;
import org.mifosng.data.command.LoanTransactionCommand;
import org.mifosng.data.command.NoteCommand;
import org.mifosng.data.command.OfficeCommand;
import org.mifosng.data.command.RoleCommand;
import org.mifosng.data.command.SignupCommand;
import org.mifosng.data.command.SubmitLoanApplicationCommand;
import org.mifosng.data.command.UndoLoanApprovalCommand;
import org.mifosng.data.command.UndoLoanDisbursalCommand;
import org.mifosng.data.command.UpdateOrganisationCurrencyCommand;
import org.mifosng.data.command.UpdateUsernamePasswordCommand;
import org.mifosng.data.command.UserCommand;
import org.mifosng.platform.client.domain.Client;
import org.mifosng.platform.client.domain.ClientRepository;
import org.mifosng.platform.client.domain.Note;
import org.mifosng.platform.client.domain.NoteRepository;
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.currency.domain.Money;
import org.mifosng.platform.exceptions.ApplicationDomainRuleException;
import org.mifosng.platform.exceptions.InvalidSignupException;
import org.mifosng.platform.exceptions.NewDataValidationException;
import org.mifosng.platform.exceptions.NoAuthorizationException;
import org.mifosng.platform.exceptions.PlatformDataIntegrityException;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.mifosng.platform.infrastructure.BasicPasswordEncodablePlatformUser;
import org.mifosng.platform.infrastructure.PlatformPasswordEncoder;
@@ -73,13 +66,11 @@ import org.mifosng.platform.loan.domain.LoanStatusRepository;
import org.mifosng.platform.loan.domain.LoanTransaction;
import org.mifosng.platform.loan.domain.LoanTransactionRepository;
import org.mifosng.platform.loan.domain.PeriodFrequencyType;
import org.mifosng.platform.loanproduct.service.LoanProductCommandValidator;
import org.mifosng.platform.organisation.domain.Office;
import org.mifosng.platform.organisation.domain.OfficeRepository;
import org.mifosng.platform.organisation.domain.Organisation;
import org.mifosng.platform.organisation.domain.OrganisationCurrency;
import org.mifosng.platform.organisation.domain.OrganisationRepository;
import org.mifosng.platform.organisation.service.OfficeCommandValidator;
import org.mifosng.platform.user.domain.AppUser;
import org.mifosng.platform.user.domain.AppUserRepository;
import org.mifosng.platform.user.domain.Permission;
@@ -88,8 +79,6 @@ import org.mifosng.platform.user.domain.PlatformUserRepository;
import org.mifosng.platform.user.domain.Role;
import org.mifosng.platform.user.domain.RoleRepository;
import org.mifosng.platform.user.domain.UserDomainService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.security.core.Authentication;
@@ -99,19 +88,14 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class WritePlatformServiceJpaRepositoryImpl implements
WritePlatformService {
public class WritePlatformServiceJpaRepositoryImpl implements WritePlatformService {
private final static Logger logger = LoggerFactory
.getLogger(WritePlatformServiceJpaRepositoryImpl.class);
private final OrganisationRepository organisationRepository;
private final OfficeRepository officeRepository;
private final UserDomainService userDomainService;
private final PlatformUserRepository platformUserRepository;
private final PlatformPasswordEncoder platformPasswordEncoder;
private final ClientRepository clientRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
private final LoanProductRepository loanProductRepository;
private final LoanRepository loanRepository;
private final LoanStatusRepository loanStatusRepository;
@@ -131,7 +115,6 @@ public class WritePlatformServiceJpaRepositoryImpl implements
final PlatformPasswordEncoder platformPasswordEncoder,
final ClientRepository clientRepository,
final NoteRepository noteRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository,
final LoanProductRepository loanProductRepository,
final LoanRepository loanRepository,
final LoanTransactionRepository loanTransactionRepository,
@@ -147,7 +130,6 @@ public class WritePlatformServiceJpaRepositoryImpl implements
this.platformPasswordEncoder = platformPasswordEncoder;
this.clientRepository = clientRepository;
this.noteRepository = noteRepository;
this.applicationCurrencyRepository = applicationCurrencyRepository;
this.loanProductRepository = loanProductRepository;
this.loanRepository = loanRepository;
this.loanTransactionRepository = loanTransactionRepository;
@@ -330,94 +312,6 @@ public class WritePlatformServiceJpaRepositoryImpl implements
return role.getId();
}
@Transactional
@Override
public Long createOffice(final OfficeCommand command) {
try {
AppUser currentUser = extractAuthenticatedUser();
OfficeCommandValidator validator = new OfficeCommandValidator(command.getName(), command.getParentId(), command.getOpeningDate(), command.getExternalId());
validator.validate();
Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId());
Office office = Office.createNew(currentUser.getOrganisation(), parent, command.getName(), command.getOpeningDate(), command.getExternalId());
// pre save to generate id for use in office hierarchy
this.officeRepository.save(office);
office.generateHierarchy();
this.officeRepository.save(office);
return office.getId();
} catch (DataIntegrityViolationException dve) {
handleOfficeDataIntegrityIssues(command, dve);
return Long.valueOf(-1);
}
}
@Transactional
@Override
public Long updateOffice(final OfficeCommand command) {
try {
AppUser currentUser = extractAuthenticatedUser();
OfficeCommandValidator validator = new OfficeCommandValidator(command.getName(), command.getParentId(), command.getOpeningDate(), command.getExternalId());
validator.validate();
Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getId());
office.update(command.getName(), command.getExternalId(), command.getOpeningDate());
this.officeRepository.save(office);
return office.getId();
} catch (DataIntegrityViolationException dve) {
handleOfficeDataIntegrityIssues(command, dve);
return Long.valueOf(-1);
}
}
/*
* Guaranteed to throw an exception no matter what the data integrity issue is.
*/
private void handleOfficeDataIntegrityIssues(final OfficeCommand command, DataIntegrityViolationException dve) {
Throwable realCause = dve.getMostSpecificCause();
if (realCause.getMessage().contains("externalid_org")) {
throw new PlatformDataIntegrityException("error.msg.office.duplicate.externalId", "Office with externalId {0} already exists", "externalId", command.getExternalId());
} else if (realCause.getMessage().contains("name_org")) {
throw new PlatformDataIntegrityException("error.msg.office.duplicate.name", "Office with name {0} already exists", "name", command.getName());
}
logger.error(dve.getMessage(), dve);
throw new PlatformDataIntegrityException("error.msg.office.unknown.data.integrity.issue", "Unknown data integrity issue with resource.");
}
/*
* used to restrict modifying operations to office that are either the users office or lower (child) in the office hierarchy
*/
private Office validateUserPriviledgeOnOfficeAndRetrieve(AppUser currentUser, Long officeId) {
Office userOffice = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), currentUser.getOffice().getId()));
if (userOffice.doesNotHaveAnOfficeInHierarchyWithId(officeId)) {
ErrorResponse error = new ErrorResponse("error.msg.office.not.authorized", "id", officeId.toString());
throw new ApplicationDomainRuleException(Arrays.asList(error), "Errors exist.");
}
Office officeToReturn = userOffice;
if (!userOffice.identifiedBy(officeId)) {
officeToReturn = this.officeRepository.findOne(officesThatMatch(currentUser.getOrganisation(), officeId));
}
return officeToReturn;
}
@Transactional
@Override
public Long signup(final SignupCommand command) {
@@ -441,75 +335,6 @@ public class WritePlatformServiceJpaRepositoryImpl implements
throw new InvalidSignupException(e);
}
}
@Transactional
@Override
public EntityIdentifier createLoanProduct(final LoanProductCommand command) {
AppUser currentUser = extractAuthenticatedUser();
LoanProductCommandValidator validator = new LoanProductCommandValidator();
validator.validateForCreate(command);
// assemble LoanProduct from data
InterestMethod interestMethod = InterestMethod.fromInt(command.getInterestMethod());
InterestCalculationPeriodMethod interestCalculationPeriodMethod = InterestCalculationPeriodMethod.fromInt(command.getInterestCalculationPeriodMethod());
AmortizationMethod amortizationMethod = AmortizationMethod.fromInt(command.getAmortizationMethod());
PeriodFrequencyType repaymentFrequencyType = PeriodFrequencyType
.fromInt(command.getRepaymentFrequency());
PeriodFrequencyType interestFrequencyType = PeriodFrequencyType
.fromInt(command.getInterestRateFrequencyMethod());
MonetaryCurrency currency = new MonetaryCurrency(command.getCurrencyCode(), command.getDigitsAfterDecimal());
// apr calculator
BigDecimal annualInterestRate = BigDecimal.ZERO;
switch (interestFrequencyType) {
case DAYS:
break;
case WEEKS:
annualInterestRate = command.getInterestRatePerPeriod().multiply(BigDecimal.valueOf(52));
break;
case MONTHS:
annualInterestRate = command.getInterestRatePerPeriod().multiply(BigDecimal.valueOf(12));
break;
case YEARS:
annualInterestRate = command.getInterestRatePerPeriod().multiply(BigDecimal.valueOf(1));
break;
case INVALID:
break;
}
LoanProduct loanproduct = new LoanProduct(currentUser.getOrganisation(), command.getName(), command.getDescription(),
currency, command.getPrincipal(),
command.getInterestRatePerPeriod(), interestFrequencyType, annualInterestRate, interestMethod, interestCalculationPeriodMethod,
command.getRepaymentEvery(), repaymentFrequencyType, command.getNumberOfRepayments(), amortizationMethod, command.getInArrearsToleranceAmount(),
command.isFlexibleRepaymentSchedule(), command.isInterestRebateAllowed());
this.loanProductRepository.save(loanproduct);
return new EntityIdentifier(loanproduct.getId());
}
@Transactional
@Override
public EntityIdentifier updateLoanProduct(LoanProductCommand command) {
AppUser currentUser = extractAuthenticatedUser();
LoanProductCommandValidator validator = new LoanProductCommandValidator();
validator.validateForUpdate(command);
LoanProduct product = this.loanProductRepository.findOne(productThatMatches(currentUser.getOrganisation(), command.getId()));
product.update(command);
this.loanProductRepository.save(product);
return new EntityIdentifier(Long.valueOf(product.getId()));
}
@Transactional
@Override
@@ -565,35 +390,6 @@ public class WritePlatformServiceJpaRepositoryImpl implements
return newClient.getId();
}
@Transactional
@Override
public void updateOrganisationCurrencies(final UpdateOrganisationCurrencyCommand command) {
AppUser currentUser = extractAuthenticatedUser();
if (command.getCodes().isEmpty()) {
List<ErrorResponse> dataValidationErrors = Arrays.asList(new ErrorResponse("validation.msg.organisation.allowed.currencies.cannot.be.blank", "selectedItems"));
throw new NewDataValidationException(dataValidationErrors, "Data validation errors exist.");
}
Set<OrganisationCurrency> allowedCurrencies = new HashSet<OrganisationCurrency>();
for (String currencyCode : command.getCodes()) {
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
OrganisationCurrency allowedCurrency = new OrganisationCurrency(
currency.getCode(), currency.getName(),
currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol());
allowedCurrencies.add(allowedCurrency);
}
Organisation org = currentUser.getOrganisation();
org.setAllowedCurrencies(allowedCurrencies);
this.organisationRepository.save(org);
}
private AppUser extractAuthenticatedUser() {
AppUser currentUser = null;
SecurityContext context = SecurityContextHolder.getContext();
@@ -0,0 +1,51 @@
package org.mifosng.platform.api.configuration;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.mifosng.data.ConfigurationData;
import org.mifosng.data.command.OrganisationCurrencyCommand;
import org.mifosng.platform.configuration.service.ConfigurationReadPlatformService;
import org.mifosng.platform.configuration.service.ConfigurationWritePlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
@Path("/v1/configurations")
@Component
@Scope("singleton")
public class ConfigurationApiResource {
@Autowired
private ConfigurationReadPlatformService configurationReadPlatformService;
@Autowired
private ConfigurationWritePlatformService configurationWritePlatformService;
@GET
@Path("currency")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({MediaType.APPLICATION_JSON})
public Response retrieveCurrencyDataForConfiguration() {
ConfigurationData configurationData = this.configurationReadPlatformService.retrieveCurrencyConfiguration();
return Response.ok().entity(configurationData).build();
}
@PUT
@Path("currency")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Produces({ MediaType.APPLICATION_JSON})
public Response updateAllowedCurrenciesForOrganisation(OrganisationCurrencyCommand command) {
this.configurationWritePlatformService.updateOrganisationCurrencies(command);
return Response.ok().entity(command).build();
}
}
@@ -2,7 +2,6 @@ package org.mifosng.platform.api.loanproduct;
import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -10,7 +9,6 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
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;
@@ -74,13 +72,11 @@ public class LoanProductApiResource {
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON})
public Response createLoanProduct(@Context HttpServletRequest request) {
public Response createLoanProduct(LoanProductCommand command) {
hardcodeUserIntoSecurityContext();
// TODO - FIX mapping to command object on post and also fix error handling of this when it fails.
EntityIdentifier entityIdentifier = new EntityIdentifier(Long.valueOf(-1));
// this.loanProductWritePlatformService.createLoanProduct(command);
EntityIdentifier entityIdentifier = this.loanProductWritePlatformService.createLoanProduct(command);
return Response.ok().entity(entityIdentifier).build();
}
@@ -1,6 +1,9 @@
package org.mifosng.platform.api.office;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -12,16 +15,22 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.joda.time.format.DateTimeFormat;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.OfficeData;
import org.mifosng.data.OfficeList;
import org.mifosng.data.command.OfficeCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosng.platform.organisation.service.OfficeReadPlatformService;
import org.mifosng.platform.organisation.service.OfficeWritePlatformService;
import org.mifosng.platform.user.domain.AppUser;
import org.mifosng.platform.user.domain.AppUserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
@@ -61,12 +70,27 @@ public class OfficeApiResource {
return Response.ok().entity(new OfficeList(offices)).build();
}
@GET
@Path("template")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({MediaType.APPLICATION_JSON})
public Response retrieveOfficeTemplate() {
hardcodeUserIntoSecurityContext();
OfficeData newOfficeTemplate = this.readPlatformService.retrieveNewOfficeTemplate();
return Response.ok().entity(newOfficeTemplate).build();
}
@POST
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON})
public Response createOffice(final OfficeCommand command) {
hardcodeUserIntoSecurityContext();
LocalDate openingDate = parseStringToLocalDate(command.getOpeningDateFormatted(), "openingDateFormatted", command.getDateFormat());
command.setOpeningDate(openingDate);
Long officeId = this.writePlatformService.createOffice(command);
return Response.ok().entity(new EntityIdentifier(officeId)).build();
@@ -89,11 +113,33 @@ public class OfficeApiResource {
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON})
public Response updateOffice(@PathParam("officeId") final Long officeId, final OfficeCommand command) {
LocalDate openingDate = parseStringToLocalDate(command.getOpeningDateFormatted(), "openingDateFormatted", command.getDateFormat());
hardcodeUserIntoSecurityContext();
command.setId(officeId);
command.setOpeningDate(openingDate);
Long entityId = this.writePlatformService.updateOffice(command);
return Response.ok().entity(new EntityIdentifier(entityId)).build();
}
private LocalDate parseStringToLocalDate(String eventDate, String dateFieldIdentifier, String dateFormat) {
LocalDate eventLocalDate = null;
if (StringUtils.isNotBlank(eventDate)) {
try {
Locale locale = LocaleContextHolder.getLocale();
eventLocalDate = DateTimeFormat.forPattern(dateFormat).withLocale(locale).parseLocalDate(eventDate.toLowerCase(locale));
} catch (IllegalArgumentException e) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.invalid.date.format", "The parameter " + dateFieldIdentifier + " is invalid.", dateFieldIdentifier, eventDate);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
}
return eventLocalDate;
}
}
@@ -0,0 +1,9 @@
package org.mifosng.platform.configuration.service;
import org.mifosng.data.ConfigurationData;
public interface ConfigurationReadPlatformService {
ConfigurationData retrieveCurrencyConfiguration();
}
@@ -0,0 +1,36 @@
package org.mifosng.platform.configuration.service;
import java.util.ArrayList;
import java.util.List;
import org.mifosng.data.ConfigurationData;
import org.mifosng.data.CurrencyData;
import org.mifosng.platform.currency.service.CurrencyReadPlatformService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ConfigurationReadPlatformServiceImpl implements ConfigurationReadPlatformService {
private final CurrencyReadPlatformService currencyReadPlatformService;
@Autowired
public ConfigurationReadPlatformServiceImpl(final CurrencyReadPlatformService currencyReadPlatformService) {
this.currencyReadPlatformService = currencyReadPlatformService;
}
@Override
public ConfigurationData retrieveCurrencyConfiguration() {
List<CurrencyData> selectedCurrencyOptions = new ArrayList<CurrencyData>(this.currencyReadPlatformService.retrieveAllowedCurrencies());
List<CurrencyData> currencyOptions = new ArrayList<CurrencyData>(this.currencyReadPlatformService.retrieveAllPlatformCurrencies());
// remove selected currency options
currencyOptions.removeAll(selectedCurrencyOptions);
ConfigurationData configurationData = new ConfigurationData();
configurationData.setCurrencyOptions(currencyOptions);
configurationData.setSelectedCurrencyOptions(selectedCurrencyOptions);
return configurationData;
}
}
@@ -0,0 +1,9 @@
package org.mifosng.platform.configuration.service;
import org.mifosng.data.command.OrganisationCurrencyCommand;
public interface ConfigurationWritePlatformService {
void updateOrganisationCurrencies(OrganisationCurrencyCommand command);
}
@@ -0,0 +1,76 @@
package org.mifosng.platform.configuration.service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.OrganisationCurrencyCommand;
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.Organisation;
import org.mifosng.platform.organisation.domain.OrganisationCurrency;
import org.mifosng.platform.organisation.domain.OrganisationRepository;
import org.mifosng.platform.security.PlatformSecurityContext;
import org.mifosng.platform.user.domain.AppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class ConfigurationWritePlatformServiceJpaRepositoryImpl implements ConfigurationWritePlatformService {
private final PlatformSecurityContext context;
private final OrganisationRepository organisationRepository;
private final ApplicationCurrencyRepository applicationCurrencyRepository;
@Autowired
public ConfigurationWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final OrganisationRepository organisationRepository,
final ApplicationCurrencyRepository applicationCurrencyRepository) {
this.context = context;
this.organisationRepository = organisationRepository;
this.applicationCurrencyRepository = applicationCurrencyRepository;
}
@Transactional
@Override
public void updateOrganisationCurrencies(final OrganisationCurrencyCommand command) {
AppUser currentUser = context.authenticatedUser();
if (command.getSelectedItems().isEmpty()) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.organisation.allowed.currencies.cannot.be.blank", "The parameter selectedItems is invalid.", "selectedItems");
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
Set<OrganisationCurrency> allowedCurrencies = new HashSet<OrganisationCurrency>();
for (String currencyCode : command.getSelectedItems()) {
ApplicationCurrency currency = this.applicationCurrencyRepository.findOneByCode(currencyCode);
if (currency == null) {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
ApiParameterError error = ApiParameterError.parameterError("validation.msg.currency.code.invalid", "The parameter selectedItems contains an invalid currency code entry.", "selectedItems", currencyCode);
dataValidationErrors.add(error);
throw new PlatformApiDataValidationException("validation.msg.validation.errors.exist", "Validation errors exist.", dataValidationErrors);
}
OrganisationCurrency allowedCurrency = new OrganisationCurrency(
currency.getCode(), currency.getName(),
currency.getDecimalPlaces(), currency.getNameCode(), currency.getDisplaySymbol());
allowedCurrencies.add(allowedCurrency);
}
Organisation org = currentUser.getOrganisation();
org.setAllowedCurrencies(allowedCurrencies);
this.organisationRepository.save(org);
}
}
@@ -17,7 +17,7 @@ public class ResponseCorsFilter implements ContainerResponseFilter {
ResponseBuilder resp = Response.fromResponse(response.getResponse());
resp.header("Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
resp.header("Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
String reqHead = request.getHeaderValue("Access-Control-Request-Headers");
@@ -6,7 +6,6 @@ import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.data.command.LoanProductCommandData;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
import org.mifosng.platform.loan.domain.AmortizationMethod;
import org.mifosng.platform.loan.domain.InterestMethod;
@@ -33,7 +32,7 @@ public class LoanProductCommandValidator {
validateRemainingAttributes(command, dataValidationErrors);
}
private void validateRemainingAttributes(LoanProductCommandData command, List<ApiParameterError> dataValidationErrors) {
private void validateRemainingAttributes(LoanProductCommand command, List<ApiParameterError> dataValidationErrors) {
if (StringUtils.isBlank(command.getName())) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.product.name.cannot.be.blank", "The parameter name cannot be blank.", "name");
@@ -38,7 +38,7 @@ public class Office extends AbstractAuditableCustom<AppUser, Long> {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent_id")
private final Office parent;
private Office parent;
@Column(name = "name", nullable = false, length=100)
private String name;
@@ -109,6 +109,10 @@ public class Office extends AbstractAuditableCustom<AppUser, Long> {
this.openingDate = newOpeningDate.toDateMidnight().toDate();
}
public void update(Office newParent) {
this.parent = newParent;
}
public boolean identifiedBy(String identifier) {
return identifier.equalsIgnoreCase(this.name) || identifier.equalsIgnoreCase(this.externalId);
}
@@ -4,45 +4,39 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.joda.time.LocalDate;
import org.mifosng.data.ApiParameterError;
import org.mifosng.data.command.OfficeCommand;
import org.mifosng.platform.exceptions.PlatformApiDataValidationException;
public class OfficeCommandValidator {
private final String name;
private final Long parentId;
private final LocalDate openingDate;
private final String externalId;
private final OfficeCommand command;
public OfficeCommandValidator(String name, Long parentId, LocalDate openingDate, String externalId) {
this.name = name;
this.parentId = parentId;
this.openingDate = openingDate;
this.externalId = externalId;
public OfficeCommandValidator(OfficeCommand command) {
this.command = command;
}
public void validate() {
List<ApiParameterError> dataValidationErrors = new ArrayList<ApiParameterError>();
if (StringUtils.isBlank(this.name)) {
if (StringUtils.isBlank(this.command.getName())) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.office.name.cannot.be.blank", "The parameter name cannot be blank.", "name");
dataValidationErrors.add(error);
}
if (this.parentId == null || parentId.intValue() <= 0) {
if (!command.isRootOffice() && (this.command.getParentId() == null || this.command.getParentId().intValue() <= 0)) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.office.parent.cannot.be.blank", "A valid parentId must be provided.", "parentId");
dataValidationErrors.add(error);
}
if (this.openingDate == null) {
if (this.command.getOpeningDate() == null) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.office.opening.date.cannot.be.blank", "The parameter openingDate cannot be blank", "openingDate");
dataValidationErrors.add(error);
}
if (StringUtils.isNotBlank(this.externalId)) {
if (this.externalId.trim().length() > 100) {
if (StringUtils.isNotBlank(this.command.getExternalId())) {
if (this.command.getExternalId().trim().length() > 100) {
ApiParameterError error = ApiParameterError.parameterError("validation.msg.office.externalId.exceeds.max.length", "The parameter externalId exceeds max length of {0}", "externalId", 100);
dataValidationErrors.add(error);
}
@@ -9,4 +9,6 @@ public interface OfficeReadPlatformService {
Collection<OfficeData> retrieveAllOffices();
OfficeData retrieveOffice(Long officeId);
OfficeData retrieveNewOfficeTemplate();
}
@@ -103,4 +103,18 @@ public class OfficeReadPlatformServiceImpl implements OfficeReadPlatformService
throw new PlatformResourceNotFoundException("error.msg.office.id.invalid", "Office with identifier {0} does not exist.", officeId);
}
}
@Override
public OfficeData retrieveNewOfficeTemplate() {
context.authenticatedUser();
List<OfficeData> allowedParents = new ArrayList<OfficeData>(retrieveAllOffices());
OfficeData officeTemplate = new OfficeData();
officeTemplate.setAllowedParents(allowedParents);
officeTemplate.setOpeningDate(new LocalDate());
return officeTemplate;
}
}
@@ -17,15 +17,15 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
public class OfficePlatformServiceJpaRepositoryImpl implements OfficeWritePlatformService {
public class OfficeWritePlatformServiceJpaRepositoryImpl implements OfficeWritePlatformService {
private final static Logger logger = LoggerFactory.getLogger(OfficePlatformServiceJpaRepositoryImpl.class);
private final static Logger logger = LoggerFactory.getLogger(OfficeWritePlatformServiceJpaRepositoryImpl.class);
private final PlatformSecurityContext context;
private final OfficeRepository officeRepository;
@Autowired
public OfficePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final OfficeRepository officeRepository) {
public OfficeWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context, final OfficeRepository officeRepository) {
this.context = context;
this.officeRepository = officeRepository;
}
@@ -37,7 +37,7 @@ public class OfficePlatformServiceJpaRepositoryImpl implements OfficeWritePlatfo
try {
AppUser currentUser = context.authenticatedUser();
OfficeCommandValidator validator = new OfficeCommandValidator(command.getName(), command.getParentId(), command.getOpeningDate(), command.getExternalId());
OfficeCommandValidator validator = new OfficeCommandValidator(command);
validator.validate();
Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId());
@@ -65,12 +65,17 @@ public class OfficePlatformServiceJpaRepositoryImpl implements OfficeWritePlatfo
try {
AppUser currentUser = context.authenticatedUser();
OfficeCommandValidator validator = new OfficeCommandValidator(command.getName(), command.getParentId(), command.getOpeningDate(), command.getExternalId());
OfficeCommandValidator validator = new OfficeCommandValidator(command);
validator.validate();
Office office = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getId());
office.update(command.getName(), command.getExternalId(), command.getOpeningDate());
if (!command.isRootOffice()) {
Office parent = validateUserPriviledgeOnOfficeAndRetrieve(currentUser, command.getParentId());
office.update(parent);
}
this.officeRepository.save(office);
@@ -1,197 +0,0 @@
package org.mifosng.platform.rest;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.mifosng.data.CurrencyData;
import org.mifosng.data.CurrencyList;
import org.mifosng.data.EnumOptionList;
import org.mifosng.data.EnumOptionReadModel;
import org.mifosng.data.ErrorResponse;
import org.mifosng.data.ErrorResponseList;
import org.mifosng.data.command.UpdateOrganisationCurrencyCommand;
import org.mifosng.platform.ReadPlatformService;
import org.mifosng.platform.WritePlatformService;
import org.mifosng.platform.exceptions.ApplicationDomainRuleException;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.mifosng.platform.exceptions.NewDataValidationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
@Path("/protected/config")
@Component
@Scope("singleton")
public class ApplicationConfigurationResource {
@Autowired
private ReadPlatformService readPlatformService;
@Autowired
private WritePlatformService writePlatformService;
@GET
@Path("currency/allowed")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response retrieveAllowedCurrenciesForOrganisation() {
List<CurrencyData> currencyOptions = this.readPlatformService
.retrieveAllowedCurrencies();
return Response.ok().entity(new CurrencyList(currencyOptions)).build();
}
@PUT
@Path("currency/update")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateAllowedCurrenciesForOrganisation(final UpdateOrganisationCurrencyCommand command) {
try {
this.writePlatformService.updateOrganisationCurrencies(command);
return Response.ok().entity(command).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("currency/all")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveAllPlatformCurrencies() {
try {
List<CurrencyData> currencyOptions = this.readPlatformService
.retrieveAllPlatformCurrencies();
return Response.ok().entity(new CurrencyList(currencyOptions)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("loan/amortization/allowed")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveAllowedLoanAmortizationMethodOptionsForOrganisation() {
try {
List<EnumOptionReadModel> options = this.readPlatformService
.retrieveLoanAmortizationMethodOptions();
return Response.ok().entity(new EnumOptionList(options)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("loan/interestcalculation/allowed")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveAllowedLoanInterestMethodOptionsForOrganisation() {
try {
List<EnumOptionReadModel> options = this.readPlatformService
.retrieveLoanInterestMethodOptions();
return Response.ok().entity(new EnumOptionList(options)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("loan/repaymentfrequency/allowed")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveAllowedRepaymentFrequencyOptionsForOrganisation() {
try {
List<EnumOptionReadModel> options = this.readPlatformService
.retrieveRepaymentFrequencyOptions();
return Response.ok().entity(new EnumOptionList(options)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("loan/interestfrequency/allowed")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveAllowedNominalInterestFrequencyOptionsForOrganisation() {
try {
List<EnumOptionReadModel> options = this.readPlatformService.retrieveInterestFrequencyOptions();
return Response.ok().entity(new EnumOptionList(options)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
}
@@ -1,146 +0,0 @@
package org.mifosng.platform.rest;
import java.util.Arrays;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.ErrorResponse;
import org.mifosng.data.ErrorResponseList;
import org.mifosng.data.LoanProductData;
import org.mifosng.data.LoanProductList;
import org.mifosng.data.command.LoanProductCommand;
import org.mifosng.platform.ReadPlatformService;
import org.mifosng.platform.WritePlatformService;
import org.mifosng.platform.exceptions.ApplicationDomainRuleException;
import org.mifosng.platform.exceptions.NewDataValidationException;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
@Path("/protected/product/loan")
@Component
@Scope("singleton")
public class LoanProductResource {
@Autowired
private ReadPlatformService readPlatformService;
@Autowired
private WritePlatformService writePlatformService;
@GET
@Path("all")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response retrieveAllLoanProducts() {
Collection<LoanProductData> products = this.readPlatformService
.retrieveAllLoanProducts();
return Response.ok().entity(new LoanProductList(products)).build();
}
@POST
@Path("new")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createLoanProduct(final LoanProductCommand command) {
try {
EntityIdentifier entityIdentifier = this.writePlatformService.createLoanProduct(command);
return Response.ok().entity(entityIdentifier).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@POST
@Path("update")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateLoanProduct(final LoanProductCommand command) {
try {
EntityIdentifier entityIdentifier = this.writePlatformService.updateLoanProduct(command);
return Response.ok().entity(entityIdentifier).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("{productId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveLoanProductDetails(@PathParam("productId") final Long productId) {
try {
LoanProductData loanProduct = this.readPlatformService.retrieveLoanProduct(productId);
return Response.ok().entity(loanProduct).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("empty")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retrieveNewLoanProductDetails() {
try {
LoanProductData loanProduct = this.readPlatformService.retrieveNewLoanProductDetails();
return Response.ok().entity(loanProduct).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
}
@@ -1,135 +0,0 @@
package org.mifosng.platform.rest;
import java.util.Arrays;
import java.util.Collection;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import org.mifosng.data.EntityIdentifier;
import org.mifosng.data.ErrorResponse;
import org.mifosng.data.ErrorResponseList;
import org.mifosng.data.OfficeData;
import org.mifosng.data.OfficeList;
import org.mifosng.data.command.OfficeCommand;
import org.mifosng.platform.ReadPlatformService;
import org.mifosng.platform.WritePlatformService;
import org.mifosng.platform.exceptions.ApplicationDomainRuleException;
import org.mifosng.platform.exceptions.UnAuthenticatedUserException;
import org.mifosng.platform.exceptions.NewDataValidationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.stereotype.Component;
@Path("/protected/office")
@Component
@Scope("singleton")
public class OfficeResource {
@Autowired
private ReadPlatformService readPlatformService;
@Autowired
private WritePlatformService writePlatformService;
@GET
@Path("all")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public Response retrieveOffices() {
try {
Collection<OfficeData> offices = this.readPlatformService.retrieveAllOffices();
return Response.ok().entity(new OfficeList(offices)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@GET
@Path("{officeId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response retreiveOffice(@PathParam("officeId") final Long officeId) {
try {
OfficeData office = this.readPlatformService.retrieveOffice(officeId);
return Response.ok().entity(office).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@POST
@Path("new")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createOffice(final OfficeCommand command) {
try {
Long officeId = this.writePlatformService.createOffice(command);
return Response.ok().entity(new EntityIdentifier(officeId)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
@POST
@Path("update")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response updateOffice(final OfficeCommand command) {
try {
Long officeId = this.writePlatformService.updateOffice(command);
return Response.ok().entity(new EntityIdentifier(officeId)).build();
} catch (UnAuthenticatedUserException e) {
throw new WebApplicationException(Response.status(Status.UNAUTHORIZED).build());
} catch (AccessDeniedException e) {
ErrorResponse errorResponse = new ErrorResponse("error.msg.no.permission", "id");
ErrorResponseList list = new ErrorResponseList(Arrays.asList(errorResponse));
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(list).build());
} catch (ApplicationDomainRuleException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getErrors())).build());
} catch (NewDataValidationException e) {
throw new WebApplicationException(Response.status(Status.BAD_REQUEST).entity(new ErrorResponseList(e.getValidationErrors())).build());
}
}
}