MIFOSX-1885
Conflicts: mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
This commit is contained in:
committed by
Vishwas Babu A J
parent
94dff21a97
commit
89377a23b4
+13
-7
@@ -55,6 +55,7 @@ import org.mifosplatform.portfolio.group.exception.InvalidGroupStateTransitionEx
|
|||||||
import org.mifosplatform.portfolio.group.serialization.GroupingTypesDataValidator;
|
import org.mifosplatform.portfolio.group.serialization.GroupingTypesDataValidator;
|
||||||
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
|
||||||
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepository;
|
||||||
|
import org.mifosplatform.portfolio.loanaccount.domain.LoanRepositoryWrapper;
|
||||||
import org.mifosplatform.portfolio.note.domain.Note;
|
import org.mifosplatform.portfolio.note.domain.Note;
|
||||||
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
import org.mifosplatform.portfolio.note.domain.NoteRepository;
|
||||||
import org.mifosplatform.portfolio.savings.domain.SavingsAccount;
|
import org.mifosplatform.portfolio.savings.domain.SavingsAccount;
|
||||||
@@ -89,6 +90,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
private final CalendarInstanceRepository calendarInstanceRepository;
|
private final CalendarInstanceRepository calendarInstanceRepository;
|
||||||
private final ConfigurationDomainService configurationDomainService;
|
private final ConfigurationDomainService configurationDomainService;
|
||||||
private final SavingsAccountRepository savingsAccountRepository;
|
private final SavingsAccountRepository savingsAccountRepository;
|
||||||
|
private final LoanRepositoryWrapper loanRepositoryWrapper;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||||
@@ -98,7 +100,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
|
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
|
||||||
final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService,
|
final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService,
|
||||||
final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService,
|
final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService,
|
||||||
final SavingsAccountRepository savingsAccountRepository) {
|
final SavingsAccountRepository savingsAccountRepository, final LoanRepositoryWrapper loanRepositoryWrapper) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.groupRepository = groupRepository;
|
this.groupRepository = groupRepository;
|
||||||
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
||||||
@@ -114,6 +116,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
this.calendarInstanceRepository = calendarInstanceRepository;
|
this.calendarInstanceRepository = calendarInstanceRepository;
|
||||||
this.configurationDomainService = configurationDomainService;
|
this.configurationDomainService = configurationDomainService;
|
||||||
this.savingsAccountRepository = savingsAccountRepository;
|
this.savingsAccountRepository = savingsAccountRepository;
|
||||||
|
this.loanRepositoryWrapper = loanRepositoryWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
||||||
@@ -184,10 +187,13 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
}
|
}
|
||||||
|
|
||||||
// pre-save to generate id for use in group hierarchy
|
// pre-save to generate id for use in group hierarchy
|
||||||
this.groupRepository.save(newGroup);
|
this.groupRepository.save(newGroup);
|
||||||
|
|
||||||
/* Generate hierarchy for a new center/group and all the child groups if they exist */
|
/*
|
||||||
newGroup.generateHierarchy();
|
* Generate hierarchy for a new center/group and all the child
|
||||||
|
* groups if they exist
|
||||||
|
*/
|
||||||
|
newGroup.generateHierarchy();
|
||||||
|
|
||||||
this.groupRepository.saveAndFlush(newGroup);
|
this.groupRepository.saveAndFlush(newGroup);
|
||||||
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);
|
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);
|
||||||
@@ -732,7 +738,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
final Set<Client> clientMembers = assembleSetOfClients(groupForUpdate.officeId(), command);
|
final Set<Client> clientMembers = assembleSetOfClients(groupForUpdate.officeId(), command);
|
||||||
|
|
||||||
// check if any client has got group loans
|
// check if any client has got group loans
|
||||||
validateForJLGLoan(groupForUpdate.getId(), clientMembers);
|
checkForActiveJLGLoans(groupForUpdate.getId(), clientMembers);
|
||||||
validateForJLGSavings(groupForUpdate.getId(), clientMembers);
|
validateForJLGSavings(groupForUpdate.getId(), clientMembers);
|
||||||
final Map<String, Object> actualChanges = new HashMap<>();
|
final Map<String, Object> actualChanges = new HashMap<>();
|
||||||
|
|
||||||
@@ -807,9 +813,9 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
private void validateForJLGLoan(final Long groupId, final Set<Client> clientMembers) {
|
private void checkForActiveJLGLoans(final Long groupId, final Set<Client> clientMembers) {
|
||||||
for (final Client client : clientMembers) {
|
for (final Client client : clientMembers) {
|
||||||
final Collection<Loan> loans = this.loanRepository.findByClientIdAndGroupId(client.getId(), groupId);
|
final Collection<Loan> loans = this.loanRepositoryWrapper.findActiveLoansByLoanIdAndGroupId(client.getId(), groupId);
|
||||||
if (!CollectionUtils.isEmpty(loans)) {
|
if (!CollectionUtils.isEmpty(loans)) {
|
||||||
final String defaultUserMessage = "Client with identifier " + client.getId()
|
final String defaultUserMessage = "Client with identifier " + client.getId()
|
||||||
+ " cannot be disassociated it has group loans.";
|
+ " cannot be disassociated it has group loans.";
|
||||||
|
|||||||
+4
@@ -92,6 +92,10 @@ public interface LoanRepository extends JpaRepository<Loan, Long>, JpaSpecificat
|
|||||||
@Query("from Loan loan where loan.client.id = :clientId and loan.group.id = :groupId")
|
@Query("from Loan loan where loan.client.id = :clientId and loan.group.id = :groupId")
|
||||||
List<Loan> findByClientIdAndGroupId(@Param("clientId") Long clientId, @Param("groupId") Long groupId);
|
List<Loan> findByClientIdAndGroupId(@Param("clientId") Long clientId, @Param("groupId") Long groupId);
|
||||||
|
|
||||||
|
@Query("from Loan loan where loan.client.id = :clientId and loan.group.id = :groupId and loan.loanStatus IN :loanStatuses")
|
||||||
|
List<Loan> findByClientIdAndGroupIdAndLoanStatus(@Param("clientId") Long clientId, @Param("groupId") Long groupId,
|
||||||
|
@Param("loanStatuses") Collection<Integer> loanStatuses);
|
||||||
|
|
||||||
@Query("from Loan loan where loan.client.id = :clientId")
|
@Query("from Loan loan where loan.client.id = :clientId")
|
||||||
List<Loan> findLoanByClientId(@Param("clientId") Long clientId);
|
List<Loan> findLoanByClientId(@Param("clientId") Long clientId);
|
||||||
|
|
||||||
|
|||||||
+11
@@ -5,6 +5,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.mifosplatform.portfolio.loanaccount.domain;
|
package org.mifosplatform.portfolio.loanaccount.domain;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
import org.mifosplatform.portfolio.loanaccount.exception.LoanNotFoundException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@@ -31,4 +35,11 @@ public class LoanRepositoryWrapper {
|
|||||||
return loan;
|
return loan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Collection<Loan> findActiveLoansByLoanIdAndGroupId(Long clientId, Long groupId) {
|
||||||
|
final Collection<Integer> loanStatuses = new ArrayList<>(Arrays.asList(LoanStatus.SUBMITTED_AND_PENDING_APPROVAL.getValue(),
|
||||||
|
LoanStatus.APPROVED.getValue(), LoanStatus.ACTIVE.getValue()));
|
||||||
|
final Collection<Loan> loans = this.repository.findByClientIdAndGroupIdAndLoanStatus(clientId, groupId, loanStatuses);
|
||||||
|
return loans;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+2
@@ -0,0 +1,2 @@
|
|||||||
|
ALTER TABLE `m_loan`
|
||||||
|
DROP FOREIGN KEY `fk_m_group_client_001`;
|
||||||
Reference in New Issue
Block a user