formatting and rename of patch files.

This commit is contained in:
Keith Woodlock
2013-02-05 20:53:44 +00:00
parent 58ee1847e3
commit 0bb4fd282b
4 changed files with 72 additions and 84 deletions
@@ -0,0 +1,6 @@
UPDATE m_product_loan SET name = CONCAT(id,'-',name);
-- concating unique value to make sure column does not contain any duplicate value
ALTER TABLE m_product_loan
ADD CONSTRAINT unq_name UNIQUE (name);
@@ -1,3 +0,0 @@
UPDATE m_product_loan SET name = CONCAT(id,'-',name); -- concating unique value to make sure column does not contain any duplicate value
ALTER TABLE m_product_loan
ADD CONSTRAINT unq_name UNIQUE (name);
@@ -38,7 +38,7 @@ import org.slf4j.LoggerFactory;
public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanProductWritePlatformService { public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanProductWritePlatformService {
private final static Logger logger = LoggerFactory.getLogger(LoanProductWritePlatformServiceJpaRepositoryImpl.class); private final static Logger logger = LoggerFactory.getLogger(LoanProductWritePlatformServiceJpaRepositoryImpl.class);
private final PlatformSecurityContext context; private final PlatformSecurityContext context;
private final LoanProductCommandFromApiJsonDeserializer fromApiJsonDeserializer; private final LoanProductCommandFromApiJsonDeserializer fromApiJsonDeserializer;
private final LoanProductRepository loanProductRepository; private final LoanProductRepository loanProductRepository;
private final AprCalculator aprCalculator; private final AprCalculator aprCalculator;
@@ -67,48 +67,41 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
@Override @Override
public CommandProcessingResult createLoanProduct(final JsonCommand command) { public CommandProcessingResult createLoanProduct(final JsonCommand command) {
try { try {
this.context.authenticatedUser(); this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForCreate(command.json()); this.fromApiJsonDeserializer.validateForCreate(command.json());
// associating fund with loan product at creation is optional for // associating fund with loan product at creation is optional for
// now. // now.
final Fund fund = findFundByIdIfProvided(command final Fund fund = findFundByIdIfProvided(command.longValueOfParameterNamed("fundId"));
.longValueOfParameterNamed("fundId"));
final Long transactionProcessingStrategyId = command final Long transactionProcessingStrategyId = command.longValueOfParameterNamed("transactionProcessingStrategyId");
.longValueOfParameterNamed("transactionProcessingStrategyId"); final LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = findStrategyByIdIfProvided(transactionProcessingStrategyId);
final LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = findStrategyByIdIfProvided(transactionProcessingStrategyId);
final String currencyCode = command final String currencyCode = command.stringValueOfParameterNamed("currencyCode");
.stringValueOfParameterNamed("currencyCode"); final Set<Charge> charges = this.assembleSetOfCharges(command, currencyCode);
final Set<Charge> charges = this.assembleSetOfCharges(command,
currencyCode);
final LoanProduct loanproduct = LoanProduct.assembleFromJson(fund, final LoanProduct loanproduct = LoanProduct.assembleFromJson(fund, loanTransactionProcessingStrategy, charges, command,
loanTransactionProcessingStrategy, charges, command, this.aprCalculator);
this.aprCalculator);
this.loanProductRepository.save(loanproduct); this.loanProductRepository.save(loanproduct);
// save accounting mappings // save accounting mappings
accountMappingWritePlatformService accountMappingWritePlatformService.createLoanProductToGLAccountMapping(loanproduct.getId(), command);
.createLoanProductToGLAccountMapping(loanproduct.getId(),
command);
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) // .withCommandId(command.commandId()) //
.withEntityId(loanproduct.getId()) // .withEntityId(loanproduct.getId()) //
.build(); .build();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
return CommandProcessingResult.empty(); return CommandProcessingResult.empty();
} }
} }
private LoanTransactionProcessingStrategy findStrategyByIdIfProvided(final Long transactionProcessingStrategyId) { private LoanTransactionProcessingStrategy findStrategyByIdIfProvided(final Long transactionProcessingStrategyId) {
LoanTransactionProcessingStrategy strategy = null; LoanTransactionProcessingStrategy strategy = null;
@@ -132,67 +125,58 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
@Override @Override
public CommandProcessingResult updateLoanProduct(final Long loanProductId, final JsonCommand command) { public CommandProcessingResult updateLoanProduct(final Long loanProductId, final JsonCommand command) {
try { try {
this.context.authenticatedUser(); this.context.authenticatedUser();
this.fromApiJsonDeserializer.validateForUpdate(command.json()); this.fromApiJsonDeserializer.validateForUpdate(command.json());
final LoanProduct product = this.loanProductRepository final LoanProduct product = this.loanProductRepository.findOne(loanProductId);
.findOne(loanProductId); if (product == null) { throw new LoanProductNotFoundException(loanProductId); }
if (product == null) {
throw new LoanProductNotFoundException(loanProductId);
}
final Map<String, Object> changes = product.update(command, final Map<String, Object> changes = product.update(command, this.aprCalculator);
this.aprCalculator);
// associating fund with loan product at creation is optional for // associating fund with loan product at creation is optional for
// now. // now.
if (changes.containsKey("fundId")) { if (changes.containsKey("fundId")) {
final Long fundId = (Long) changes.get("fundId"); final Long fundId = (Long) changes.get("fundId");
final Fund fund = findFundByIdIfProvided(fundId); final Fund fund = findFundByIdIfProvided(fundId);
product.update(fund); product.update(fund);
} }
if (changes.containsKey("transactionProcessingStrategyId")) { if (changes.containsKey("transactionProcessingStrategyId")) {
final Long transactionProcessingStrategyId = (Long) changes final Long transactionProcessingStrategyId = (Long) changes.get("transactionProcessingStrategyId");
.get("transactionProcessingStrategyId"); final LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = findStrategyByIdIfProvided(transactionProcessingStrategyId);
final LoanTransactionProcessingStrategy loanTransactionProcessingStrategy = findStrategyByIdIfProvided(transactionProcessingStrategyId); product.update(loanTransactionProcessingStrategy);
product.update(loanTransactionProcessingStrategy); }
}
if (changes.containsKey("charges")) { if (changes.containsKey("charges")) {
final Set<Charge> charges = this.assembleSetOfCharges(command, final Set<Charge> charges = this.assembleSetOfCharges(command, product.getCurrency().getCode());
product.getCurrency().getCode()); product.update(charges);
product.update(charges); }
}
// accounting related changes // accounting related changes
boolean accountingTypeChanged = changes boolean accountingTypeChanged = changes.containsKey("accountingType");
.containsKey("accountingType"); if (accountingTypeChanged) {
if (accountingTypeChanged) { accountMappingWritePlatformService.updateLoanProductToGLAccountMapping(product.getId(), command, accountingTypeChanged);
accountMappingWritePlatformService }
.updateLoanProductToGLAccountMapping(product.getId(),
command, accountingTypeChanged);
}
if (!changes.isEmpty()) { if (!changes.isEmpty()) {
this.loanProductRepository.saveAndFlush(product); this.loanProductRepository.saveAndFlush(product);
} }
return new CommandProcessingResultBuilder() // return new CommandProcessingResultBuilder() //
.withCommandId(command.commandId()) // .withCommandId(command.commandId()) //
.withEntityId(loanProductId) // .withEntityId(loanProductId) //
.with(changes) // .with(changes) //
.build(); .build();
} catch (DataIntegrityViolationException dve) { } catch (DataIntegrityViolationException dve) {
handleDataIntegrityIssues(command, dve); handleDataIntegrityIssues(command, dve);
return new CommandProcessingResult(Long.valueOf(-1)); return new CommandProcessingResult(Long.valueOf(-1));
} }
} }
private Set<Charge> assembleSetOfCharges(final JsonCommand command, final String currencyCode) { private Set<Charge> assembleSetOfCharges(final JsonCommand command, final String currencyCode) {
@@ -222,6 +206,7 @@ public class LoanProductWritePlatformServiceJpaRepositoryImpl implements LoanPro
return charges; return charges;
} }
/* /*
* Guaranteed to throw an exception no matter what the data integrity issue * Guaranteed to throw an exception no matter what the data integrity issue
* is. * is.