Merge branch 'MIFOSX-1175' of git://github.com/Musoni/mifosx into Musoni-MIFOSX-1175
Conflicts: mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/domain/Group.java mifosng-provider/src/main/java/org/mifosplatform/portfolio/group/service/GroupingTypesWritePlatformServiceJpaRepositoryImpl.java
This commit is contained in:
Regular → Executable
+1
@@ -43,6 +43,7 @@ public class GroupingTypesApiConstants {
|
||||
public static final String groupMembersParamName = "groupMembers";
|
||||
|
||||
public static final String submittedOnDateParamName = "submittedOnDate";
|
||||
public static final String inheritStaffForClientAccounts = "inheritStaffForClientAccounts";
|
||||
|
||||
// group parameters
|
||||
public static final String centerIdParamName = "centerId";
|
||||
|
||||
Regular → Executable
@@ -617,4 +617,7 @@ public final class Group extends AbstractPersistable<Long> {
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
|
||||
public Set<Client> getClientMembers() {
|
||||
return this.clientMembers;
|
||||
}
|
||||
}
|
||||
Regular → Executable
+6
-1
@@ -368,7 +368,7 @@ public final class GroupingTypesDataValidator {
|
||||
|
||||
final Type typeOfMap = new TypeToken<Map<String, Object>>() {}.getType();
|
||||
|
||||
final Set<String> supportedParametersAssignStaff = new HashSet<>(Arrays.asList(GroupingTypesApiConstants.staffIdParamName));
|
||||
final Set<String> supportedParametersAssignStaff = new HashSet<>(Arrays.asList(GroupingTypesApiConstants.staffIdParamName,GroupingTypesApiConstants.inheritStaffForClientAccounts));
|
||||
|
||||
this.fromApiJsonHelper.checkForUnsupportedParameters(typeOfMap, json, supportedParametersAssignStaff);
|
||||
final JsonElement element = this.fromApiJsonHelper.parse(json);
|
||||
@@ -382,6 +382,11 @@ public final class GroupingTypesDataValidator {
|
||||
final Long staffId = this.fromApiJsonHelper.extractLongNamed(staffIdParameterName, element);
|
||||
baseDataValidator.reset().parameter(staffIdParameterName).value(staffId).notNull().longGreaterThanZero();
|
||||
|
||||
final String inheritStaffForClientAccountsParamName = GroupingTypesApiConstants.inheritStaffForClientAccounts;
|
||||
final Boolean inheritStaffForClientAccounts= this.fromApiJsonHelper.extractBooleanNamed(inheritStaffForClientAccountsParamName,element);
|
||||
baseDataValidator.reset().parameter(inheritStaffForClientAccountsParamName).value(inheritStaffForClientAccounts).ignoreIfNull().notBlank().isOneOfTheseValues(true, false);
|
||||
|
||||
|
||||
if (!dataValidationErrors.isEmpty()) { throw new PlatformApiDataValidationException(dataValidationErrors); }
|
||||
}
|
||||
|
||||
|
||||
Regular → Executable
+39
-4
@@ -88,6 +88,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
private final CommandProcessingService commandProcessingService;
|
||||
private final CalendarInstanceRepository calendarInstanceRepository;
|
||||
private final ConfigurationDomainService configurationDomainService;
|
||||
private final SavingsAccountRepository savingsAccountRepository;
|
||||
|
||||
@Autowired
|
||||
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||
@@ -96,7 +97,8 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
final GroupLevelRepository groupLevelRepository, final GroupingTypesDataValidator fromApiJsonDeserializer,
|
||||
final LoanRepository loanRepository, final SavingsAccountRepository savingsRepository,
|
||||
final CodeValueRepositoryWrapper codeValueRepository, final CommandProcessingService commandProcessingService,
|
||||
final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService) {
|
||||
final CalendarInstanceRepository calendarInstanceRepository, final ConfigurationDomainService configurationDomainService,
|
||||
final SavingsAccountRepository savingsAccountRepository) {
|
||||
this.context = context;
|
||||
this.groupRepository = groupRepository;
|
||||
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
||||
@@ -111,6 +113,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
this.commandProcessingService = commandProcessingService;
|
||||
this.calendarInstanceRepository = calendarInstanceRepository;
|
||||
this.configurationDomainService = configurationDomainService;
|
||||
this.savingsAccountRepository = savingsAccountRepository;
|
||||
}
|
||||
|
||||
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
||||
@@ -427,7 +430,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandProcessingResult assignGroupOrCenterStaff(final Long grouptId, final JsonCommand command) {
|
||||
public CommandProcessingResult assignGroupOrCenterStaff(final Long groupId, final JsonCommand command) {
|
||||
|
||||
this.context.authenticatedUser();
|
||||
|
||||
@@ -435,13 +438,45 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
|
||||
this.fromApiJsonDeserializer.validateForAssignStaff(command.json());
|
||||
|
||||
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(grouptId);
|
||||
final Group groupForUpdate = this.groupRepository.findOneWithNotFoundDetection(groupId);
|
||||
|
||||
Staff staff = null;
|
||||
final Long staffId = command.longValueOfParameterNamed(GroupingTypesApiConstants.staffIdParamName);
|
||||
|
||||
final boolean inheritStaffForClientAccounts = command
|
||||
.booleanPrimitiveValueOfParameterNamed(GroupingTypesApiConstants.inheritStaffForClientAccounts);
|
||||
staff = this.staffRepository.findByOfficeHierarchyWithNotFoundDetection(staffId, groupForUpdate.getOffice().getHierarchy());
|
||||
groupForUpdate.updateStaff(staff);
|
||||
|
||||
if (inheritStaffForClientAccounts) {
|
||||
LocalDate loanOfficerReassignmentDate = LocalDate.now();
|
||||
/*
|
||||
* update loan officer for client and update loan officer for
|
||||
* clients loans and savings
|
||||
*/
|
||||
Set<Client> clients = groupForUpdate.getClientMembers();
|
||||
if (clients != null) {
|
||||
for (Client client : clients) {
|
||||
client.updateStaff(staff);
|
||||
if (this.loanRepository.doNonClosedLoanAccountsExistForClient(client.getId())) {
|
||||
for (final Loan loan : this.loanRepository.findLoanByClientId(client.getId())) {
|
||||
if (loan.isDisbursed() && !loan.isClosed()) {
|
||||
loan.reassignLoanOfficer(staff, loanOfficerReassignmentDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.savingsAccountRepository.doNonClosedSavingAccountsExistForClient(client.getId())) {
|
||||
for (final SavingsAccount savingsAccount : this.savingsAccountRepository
|
||||
.findSavingAccountByClientId(client.getId())) {
|
||||
if (!savingsAccount.isClosed()) {
|
||||
savingsAccount.update(staff);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.groupRepository.saveAndFlush(groupForUpdate);
|
||||
|
||||
actualChanges.put(GroupingTypesApiConstants.staffIdParamName, staffId);
|
||||
@@ -449,7 +484,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
return new CommandProcessingResultBuilder() //
|
||||
.withOfficeId(groupForUpdate.officeId()) //
|
||||
.withEntityId(groupForUpdate.getId()) //
|
||||
.withGroupId(grouptId) //
|
||||
.withGroupId(groupId) //
|
||||
.with(actualChanges) //
|
||||
.build();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user