Merge pull request #774 from pramodn02/MIFOSX-929
MIFOSX-929 - added check for multiple permission for client
This commit is contained in:
+3
@@ -9,11 +9,14 @@ import org.mifosplatform.commands.domain.CommandSource;
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
import org.mifosplatform.useradministration.domain.AppUser;
|
||||
|
||||
public interface CommandProcessingService {
|
||||
|
||||
CommandProcessingResult processAndLogCommand(CommandWrapper wrapper, JsonCommand command, boolean isApprovedByChecker);
|
||||
|
||||
CommandProcessingResult logCommand(CommandSource commandSourceResult);
|
||||
|
||||
boolean validateCommand(final CommandWrapper commandWrapper,final AppUser user);
|
||||
|
||||
}
|
||||
+10
-4
@@ -53,8 +53,7 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
public CommandProcessingResult processAndLogCommand(final CommandWrapper wrapper, final JsonCommand command,
|
||||
final boolean isApprovedByChecker) {
|
||||
|
||||
final boolean rollbackTransaction = this.configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName())
|
||||
&& !isApprovedByChecker;
|
||||
final boolean rollbackTransaction = this.configurationDomainService.isMakerCheckerEnabledForTask(wrapper.taskPermissionName());
|
||||
|
||||
final NewCommandSourceHandler handler = findCommandHandler(wrapper);
|
||||
final CommandProcessingResult result = handler.processCommand(command);
|
||||
@@ -86,8 +85,8 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
this.commandSourceRepository.save(commandSourceResult);
|
||||
}
|
||||
|
||||
if (rollbackTransaction) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); }
|
||||
|
||||
if ((rollbackTransaction || result.isRollbackTransaction()) && !isApprovedByChecker) { throw new RollbackTransactionAsCommandIsNotApprovedByCheckerException(commandSourceResult); }
|
||||
result.setRollbackTransaction(null);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -627,4 +626,11 @@ public class SynchronousCommandProcessingService implements CommandProcessingSer
|
||||
|
||||
return handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateCommand(final CommandWrapper commandWrapper, final AppUser user) {
|
||||
boolean rollbackTransaction = this.configurationDomainService.isMakerCheckerEnabledForTask(commandWrapper.taskPermissionName());
|
||||
user.validateHasPermissionTo(commandWrapper.getTaskPermissionName());
|
||||
return rollbackTransaction;
|
||||
}
|
||||
}
|
||||
|
||||
+15
-3
@@ -26,12 +26,13 @@ public class CommandProcessingResult {
|
||||
@SuppressWarnings("unused")
|
||||
private final String resourceIdentifier;
|
||||
private final Long productId;
|
||||
private Boolean rollbackTransaction;
|
||||
|
||||
public static CommandProcessingResult fromDetails(final Long commandId, final Long officeId, final Long groupId, final Long clientId,
|
||||
final Long loanId, final Long savingsId, final String resourceIdentifier, final Long entityId, final String transactionId,
|
||||
final Map<String, Object> changes, final Long productId) {
|
||||
final Map<String, Object> changes, final Long productId,final Boolean rollbackTransaction) {
|
||||
return new CommandProcessingResult(commandId, officeId, groupId, clientId, loanId, savingsId, resourceIdentifier, entityId,
|
||||
transactionId, changes, productId);
|
||||
transactionId, changes, productId,rollbackTransaction);
|
||||
}
|
||||
|
||||
public static CommandProcessingResult commandOnlyResult(final Long commandId) {
|
||||
@@ -85,7 +86,7 @@ public class CommandProcessingResult {
|
||||
|
||||
private CommandProcessingResult(final Long commandId, final Long officeId, final Long groupId, final Long clientId, final Long loanId,
|
||||
final Long savingsId, final String resourceIdentifier, final Long resourceId, final String transactionId,
|
||||
final Map<String, Object> changesOnly, final Long productId) {
|
||||
final Map<String, Object> changesOnly, final Long productId, Boolean rollbackTransaction) {
|
||||
this.commandId = commandId;
|
||||
this.officeId = officeId;
|
||||
this.groupId = groupId;
|
||||
@@ -97,6 +98,7 @@ public class CommandProcessingResult {
|
||||
this.changes = changesOnly;
|
||||
this.transactionId = transactionId;
|
||||
this.productId = productId;
|
||||
this.rollbackTransaction = rollbackTransaction;
|
||||
}
|
||||
|
||||
private CommandProcessingResult(final Long resourceId, final Long officeId, final Long commandId, final Map<String, Object> changesOnly) {
|
||||
@@ -169,4 +171,14 @@ public class CommandProcessingResult {
|
||||
public Long getProductId() {
|
||||
return this.productId;
|
||||
}
|
||||
|
||||
|
||||
public boolean isRollbackTransaction() {
|
||||
return this.rollbackTransaction!=null && this.rollbackTransaction;
|
||||
}
|
||||
|
||||
|
||||
public void setRollbackTransaction(Boolean rollbackTransaction) {
|
||||
this.rollbackTransaction = rollbackTransaction;
|
||||
}
|
||||
}
|
||||
+7
-1
@@ -24,10 +24,11 @@ public class CommandProcessingResultBuilder {
|
||||
private String transactionId;
|
||||
private Map<String, Object> changes;
|
||||
private Long productId;
|
||||
private boolean rollbackTransaction = false;
|
||||
|
||||
public CommandProcessingResult build() {
|
||||
return CommandProcessingResult.fromDetails(this.commandId, this.officeId, this.groupId, this.clientId, this.loanId, this.savingsId,
|
||||
this.resourceIdentifier, this.entityId, this.transactionId, this.changes, this.productId);
|
||||
this.resourceIdentifier, this.entityId, this.transactionId, this.changes, this.productId,this.rollbackTransaction);
|
||||
}
|
||||
|
||||
public CommandProcessingResultBuilder withCommandId(final Long withCommandId) {
|
||||
@@ -84,5 +85,10 @@ public class CommandProcessingResultBuilder {
|
||||
this.productId = productId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CommandProcessingResultBuilder setRollbackTransaction(final boolean rollbackTransaction) {
|
||||
this.rollbackTransaction = this.rollbackTransaction || rollbackTransaction;
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
+23
-9
@@ -13,6 +13,9 @@ import java.util.Map;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandProcessingService;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.infrastructure.codes.domain.CodeValue;
|
||||
import org.mifosplatform.infrastructure.codes.domain.CodeValueRepositoryWrapper;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
@@ -77,6 +80,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
private final SavingsAccountRepository savingsRepository;
|
||||
private final SavingsProductRepository savingsProductRepository;
|
||||
private final SavingsApplicationProcessWritePlatformService savingsApplicationProcessWritePlatformService;
|
||||
private final CommandProcessingService commandProcessingService;
|
||||
|
||||
@Autowired
|
||||
public ClientWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||
@@ -85,7 +89,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
final GroupRepository groupRepository, final StaffRepositoryWrapper staffRepository,
|
||||
final CodeValueRepositoryWrapper codeValueRepository, final LoanRepository loanRepository,
|
||||
final SavingsAccountRepository savingsRepository,final SavingsProductRepository savingsProductRepository,
|
||||
final SavingsApplicationProcessWritePlatformService savingsApplicationProcessWritePlatformService) {
|
||||
final SavingsApplicationProcessWritePlatformService savingsApplicationProcessWritePlatformService,
|
||||
final CommandProcessingService commandProcessingService) {
|
||||
this.context = context;
|
||||
this.clientRepository = clientRepository;
|
||||
this.officeRepository = officeRepository;
|
||||
@@ -99,6 +104,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
this.savingsRepository = savingsRepository;
|
||||
this.savingsProductRepository = savingsProductRepository;
|
||||
this.savingsApplicationProcessWritePlatformService = savingsApplicationProcessWritePlatformService;
|
||||
this.commandProcessingService = commandProcessingService;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@@ -185,6 +191,11 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
}
|
||||
|
||||
final Client newClient = Client.createNew(currentUser,clientOffice, clientParentGroup, staff, savingsProduct, command);
|
||||
boolean rollbackTransaction = false;
|
||||
if(newClient.isActive()){
|
||||
final CommandWrapper commandWrapper = new CommandWrapperBuilder().activateClient(null).build();
|
||||
rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper, currentUser);
|
||||
}
|
||||
|
||||
this.clientRepository.save(newClient);
|
||||
|
||||
@@ -197,7 +208,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
|
||||
final Locale locale = command.extractLocale();
|
||||
final DateTimeFormatter fmt = DateTimeFormat.forPattern(command.dateFormat()).withLocale(locale);
|
||||
Long savingsId = openOverdraftSavingsAccount(newClient, fmt);
|
||||
CommandProcessingResult result = openOverdraftSavingsAccount(newClient, fmt);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withCommandId(command.commandId()) //
|
||||
@@ -205,7 +216,9 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
.withClientId(newClient.getId()) //
|
||||
.withGroupId(groupId) //
|
||||
.withEntityId(newClient.getId()) //
|
||||
.withSavingsId(savingsId)//
|
||||
.withSavingsId(result.getSavingsId())//
|
||||
.setRollbackTransaction(rollbackTransaction)//
|
||||
.setRollbackTransaction(result.isRollbackTransaction())//
|
||||
.build();
|
||||
} catch (final DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
@@ -284,7 +297,7 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
|
||||
final AppUser currentUser = this.context.authenticatedUser();
|
||||
client.activate(currentUser, fmt, activationDate);
|
||||
Long savingsId = openOverdraftSavingsAccount(client, fmt);
|
||||
CommandProcessingResult result = openOverdraftSavingsAccount(client, fmt);
|
||||
this.clientRepository.saveAndFlush(client);
|
||||
|
||||
return new CommandProcessingResultBuilder() //
|
||||
@@ -292,7 +305,8 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
.withOfficeId(client.officeId()) //
|
||||
.withClientId(clientId) //
|
||||
.withEntityId(clientId) //
|
||||
.withSavingsId(savingsId)//
|
||||
.withSavingsId(result.getSavingsId())//
|
||||
.setRollbackTransaction(result.isRollbackTransaction())//
|
||||
.build();
|
||||
} catch (final DataIntegrityViolationException dve) {
|
||||
handleDataIntegrityIssues(command, dve);
|
||||
@@ -300,17 +314,17 @@ public class ClientWritePlatformServiceJpaRepositoryImpl implements ClientWriteP
|
||||
}
|
||||
}
|
||||
|
||||
private Long openOverdraftSavingsAccount(final Client client, final DateTimeFormatter fmt) {
|
||||
Long accountId = null;
|
||||
private CommandProcessingResult openOverdraftSavingsAccount(final Client client, final DateTimeFormatter fmt) {
|
||||
CommandProcessingResult commandProcessingResult = CommandProcessingResult.empty();
|
||||
if(client.isActive() && client.SavingsProduct() != null){
|
||||
if(!client.SavingsProduct().isAllowOverdraft()){
|
||||
String defaultUserMessage = "Client's saving account must be a overdraft account";
|
||||
throw new InvalidClientSavingProductException("saving.product", "must.be.ovrdraft.account", defaultUserMessage, client.SavingsProduct().getId(),client.getId());
|
||||
}
|
||||
SavingsAccountDataDTO savingsAccountDataDTO = new SavingsAccountDataDTO(client, null, client.SavingsProduct(), client.getActivationLocalDate(), client.activatedBy(), fmt);
|
||||
accountId = this.savingsApplicationProcessWritePlatformService.createActiveApplication(savingsAccountDataDTO);
|
||||
commandProcessingResult = this.savingsApplicationProcessWritePlatformService.createActiveApplication(savingsAccountDataDTO);
|
||||
}
|
||||
return accountId;
|
||||
return commandProcessingResult;
|
||||
}
|
||||
|
||||
private void logAsErrorUnexpectedDataIntegrityException(final DataIntegrityViolationException dve) {
|
||||
|
||||
+1
-1
@@ -25,5 +25,5 @@ public interface SavingsApplicationProcessWritePlatformService {
|
||||
|
||||
CommandProcessingResult applicantWithdrawsFromApplication(Long savingsId, JsonCommand command);
|
||||
|
||||
Long createActiveApplication(SavingsAccountDataDTO savingsAccountDataDTO);
|
||||
CommandProcessingResult createActiveApplication(SavingsAccountDataDTO savingsAccountDataDTO);
|
||||
}
|
||||
+15
-5
@@ -8,14 +8,15 @@ package org.mifosplatform.portfolio.savings.service;
|
||||
import static org.mifosplatform.portfolio.savings.SavingsApiConstants.SAVINGS_ACCOUNT_RESOURCE_NAME;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.mifosplatform.commands.domain.CommandWrapper;
|
||||
import org.mifosplatform.commands.service.CommandProcessingService;
|
||||
import org.mifosplatform.commands.service.CommandWrapperBuilder;
|
||||
import org.mifosplatform.infrastructure.core.api.JsonCommand;
|
||||
import org.mifosplatform.infrastructure.core.data.ApiParameterError;
|
||||
import org.mifosplatform.infrastructure.core.data.CommandProcessingResult;
|
||||
@@ -75,6 +76,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
private final StaffRepositoryWrapper staffRepository;
|
||||
private final SavingsAccountApplicationTransitionApiJsonValidator savingsAccountApplicationTransitionApiJsonValidator;
|
||||
private final SavingsAccountChargeAssembler savingsAccountChargeAssembler;
|
||||
private final CommandProcessingService commandProcessingService;
|
||||
|
||||
@Autowired
|
||||
public SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||
@@ -84,7 +86,8 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
final GroupRepository groupRepository, final SavingsProductRepository savingsProductRepository,
|
||||
final NoteRepository noteRepository, final StaffRepositoryWrapper staffRepository,
|
||||
final SavingsAccountApplicationTransitionApiJsonValidator savingsAccountApplicationTransitionApiJsonValidator,
|
||||
final SavingsAccountChargeAssembler savingsAccountChargeAssembler) {
|
||||
final SavingsAccountChargeAssembler savingsAccountChargeAssembler,
|
||||
final CommandProcessingService commandProcessingService) {
|
||||
this.context = context;
|
||||
this.savingAccountRepository = savingAccountRepository;
|
||||
this.savingAccountAssembler = savingAccountAssembler;
|
||||
@@ -97,6 +100,7 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
this.staffRepository = staffRepository;
|
||||
this.savingsAccountApplicationTransitionApiJsonValidator = savingsAccountApplicationTransitionApiJsonValidator;
|
||||
this.savingsAccountChargeAssembler = savingsAccountChargeAssembler;
|
||||
this.commandProcessingService = commandProcessingService;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -433,7 +437,10 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long createActiveApplication(final SavingsAccountDataDTO savingsAccountDataDTO) {
|
||||
public CommandProcessingResult createActiveApplication(final SavingsAccountDataDTO savingsAccountDataDTO) {
|
||||
|
||||
final CommandWrapper commandWrapper = new CommandWrapperBuilder().savingsAccountActivation(null).build();
|
||||
boolean rollbackTransaction = this.commandProcessingService.validateCommand(commandWrapper, savingsAccountDataDTO.getAppliedBy());
|
||||
|
||||
final SavingsAccount account = this.savingAccountAssembler.assembleFrom(savingsAccountDataDTO.getClient(),savingsAccountDataDTO.getGroup(),
|
||||
savingsAccountDataDTO.getSavingsProduct(),savingsAccountDataDTO.getApplicationDate(),savingsAccountDataDTO.getAppliedBy());
|
||||
@@ -446,6 +453,9 @@ public class SavingsApplicationProcessWritePlatformServiceJpaRepositoryImpl impl
|
||||
account.updateAccountNo(accountNoGenerator.generate());
|
||||
this.savingAccountRepository.save(account);
|
||||
}
|
||||
return account.getId();
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withSavingsId(account.getId()) //
|
||||
.setRollbackTransaction(rollbackTransaction)//
|
||||
.build();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user