MIFOSX-1885

Conflicts:
	mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
This commit is contained in:
sachinkulkarni12
2015-03-19 16:57:35 +05:30
committed by Vishwas Babu A J
parent 94dff21a97
commit 89377a23b4
4 changed files with 34 additions and 11 deletions
@@ -55,6 +55,7 @@ import org.mifosplatform.portfolio.group.exception.InvalidGroupStateTransitionEx
import org.mifosplatform.portfolio.group.serialization.GroupingTypesDataValidator;
import org.mifosplatform.portfolio.loanaccount.domain.Loan;
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.NoteRepository;
import org.mifosplatform.portfolio.savings.domain.SavingsAccount;
@@ -89,6 +90,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
private final CalendarInstanceRepository calendarInstanceRepository;
private final ConfigurationDomainService configurationDomainService;
private final SavingsAccountRepository savingsAccountRepository;
private final LoanRepositoryWrapper loanRepositoryWrapper;
@Autowired
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
@@ -98,7 +100,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService,
final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService,
final SavingsAccountRepository savingsAccountRepository) {
final SavingsAccountRepository savingsAccountRepository, final LoanRepositoryWrapper loanRepositoryWrapper) {
this.context = context;
this.groupRepository = groupRepository;
this.clientRepositoryWrapper = clientRepositoryWrapper;
@@ -114,6 +116,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
this.calendarInstanceRepository = calendarInstanceRepository;
this.configurationDomainService = configurationDomainService;
this.savingsAccountRepository = savingsAccountRepository;
this.loanRepositoryWrapper = loanRepositoryWrapper;
}
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
@@ -131,7 +134,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
parentGroup = this.groupRepository.findOneWithNotFoundDetection(centerId);
officeId = parentGroup.officeId();
}
final Office groupOffice = this.officeRepository.findOne(officeId);
if (groupOffice == null) { throw new OfficeNotFoundException(officeId); }
@@ -184,10 +187,13 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
}
// 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);
newGroup.captureStaffHistoryDuringCenterCreation(staff, activationDate);
@@ -415,7 +421,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
groupForUpdate.unassignStaff();
}
this.groupRepository.saveAndFlush(groupForUpdate);
actualChanges.put(staffIdParamName, null);
return new CommandProcessingResultBuilder() //
@@ -732,7 +738,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final Set<Client> clientMembers = assembleSetOfClients(groupForUpdate.officeId(), command);
// check if any client has got group loans
validateForJLGLoan(groupForUpdate.getId(), clientMembers);
checkForActiveJLGLoans(groupForUpdate.getId(), clientMembers);
validateForJLGSavings(groupForUpdate.getId(), clientMembers);
final Map<String, Object> actualChanges = new HashMap<>();
@@ -760,14 +766,14 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
final Group centerForUpdate = this.groupRepository.findOneWithNotFoundDetection(centerId);
final Set<Group> groupMembers = assembleSetOfChildGroups(centerForUpdate.officeId(), command);
checkGroupMembersMeetingSyncWithCenterMeeting(centerId, groupMembers);
final Map<String, Object> actualChanges = new HashMap<>();
final List<String> changes = centerForUpdate.associateGroups(groupMembers);
if (!changes.isEmpty()) {
actualChanges.put(GroupingTypesApiConstants.groupMembersParamName, changes);
}
this.groupRepository.saveAndFlush(centerForUpdate);
return new CommandProcessingResultBuilder() //
@@ -807,9 +813,9 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
}
@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) {
final Collection<Loan> loans = this.loanRepository.findByClientIdAndGroupId(client.getId(), groupId);
final Collection<Loan> loans = this.loanRepositoryWrapper.findActiveLoansByLoanIdAndGroupId(client.getId(), groupId);
if (!CollectionUtils.isEmpty(loans)) {
final String defaultUserMessage = "Client with identifier " + client.getId()
+ " cannot be disassociated it has group loans.";
@@ -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")
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")
List<Loan> findLoanByClientId(@Param("clientId") Long clientId);
@@ -5,6 +5,10 @@
*/
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -31,4 +35,11 @@ public class LoanRepositoryWrapper {
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;
}
}
@@ -0,0 +1,2 @@
ALTER TABLE `m_loan`
DROP FOREIGN KEY `fk_m_group_client_001`;