MIFOSX-1175 add extra param to assign staff to group with integration test
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
Regular → Executable
+4
@@ -567,4 +567,8 @@ public final class Group extends AbstractPersistable<Long> {
|
||||
|
||||
return differences;
|
||||
}
|
||||
|
||||
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
Regular → Executable
+36
-4
@@ -88,6 +88,8 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
private final SavingsAccountRepository savingsRepository;
|
||||
private final CommandProcessingService commandProcessingService;
|
||||
private final CalendarInstanceRepository calendarInstanceRepository;
|
||||
private final SavingsAccountRepository savingsAccountRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
public GroupingTypesWritePlatformServiceJpaRepositoryImpl(final PlatformSecurityContext context,
|
||||
@@ -96,7 +98,7 @@ 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 CalendarInstanceRepository calendarInstanceRepository,final SavingsAccountRepository savingsAccountRepository) {
|
||||
this.context = context;
|
||||
this.groupRepository = groupRepository;
|
||||
this.clientRepositoryWrapper = clientRepositoryWrapper;
|
||||
@@ -110,6 +112,7 @@ public class GroupingTypesWritePlatformServiceJpaRepositoryImpl implements Group
|
||||
this.codeValueRepository = codeValueRepository;
|
||||
this.commandProcessingService = commandProcessingService;
|
||||
this.calendarInstanceRepository = calendarInstanceRepository;
|
||||
this.savingsAccountRepository = savingsAccountRepository;
|
||||
}
|
||||
|
||||
private CommandProcessingResult createGroupingType(final JsonCommand command, final GroupTypes groupingType, final Long centerId) {
|
||||
@@ -405,7 +408,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();
|
||||
|
||||
@@ -413,13 +416,42 @@ 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);
|
||||
@@ -427,7 +459,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