final Group destinationGroup = this.groupRepository.findOneWithNotFoundDetection(destinationGroupId);
final Long staffId = jsonCommand.longValueOfParameterNamed(TransferApiConstants.newStaffIdParamName);
final Boolean inheritDestinationGroupLoanOfficer = jsonCommand
.booleanObjectValueOfParameterNamed(TransferApiConstants.inheritDestinationGroupLoanOfficer);
Staff staff = null;
final Office sourceOffice = sourceGroup.getOffice();
if (staffId != null) {
staff = this.staffRepositoryWrapper.findByOfficeHierarchyWithNotFoundDetection(staffId, sourceOffice.getHierarchy());
}
final List<Client> clients = assembleListOfClients(jsonCommand);
if (sourceGroupId == destinationGroupId) { throw new TransferNotSupportedException(
TRANSFER_NOT_SUPPORTED_REASON.SOURCE_AND_DESTINATION_GROUP_CANNOT_BE_SAME, sourceGroupId, destinationGroupId); }
/*** Do not allow bulk client transfers across branches ***/
if (!(sourceOffice.getId() == destinationGroup.getOffice().getId())) { throw new TransferNotSupportedException(
TRANSFER_NOT_SUPPORTED_REASON.BULK_CLIENT_TRANSFER_ACROSS_BRANCHES, sourceGroupId, destinationGroupId); }
for (final Client client : clients) {
transferClientBetweenGroups(sourceGroup, client, destinationGroup, inheritDestinationGroupLoanOfficer, staff);
}