Skip to content

Commit

Permalink
#663 | Minor method extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
himeshr committed Dec 11, 2023
1 parent 38e5b4e commit 39c0469
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,7 @@ public List<UserSubjectAssignment> assignSubjects(User user, List<Individual> su
List<Individual> listOfSubjects = subjectTypeList.getValue();
List<Long> addressLevels = addressLevelService.getAllRegistrationAddressIdsBySubjectType(user.getCatchment(), subjectType);
for (Individual subject : listOfSubjects) {
try {
checkIfSubjectLiesWithinUserCatchment(assignmentVoided, subject, addressLevels);
checkIfSubjectIsPartOfGroupAssignedToUser(assignmentVoided, user, subject);
createUpdateAssignment(assignmentVoided, userSubjectAssignmentList, user, subject);
} catch (Exception ve) {
errors.add(ve.getMessage());
}
validateAndCreateUpdateUserSubjectAssignment(assignmentVoided, user, subject, userSubjectAssignmentList, addressLevels, errors);
}
}
if(errors.isEmpty()) {
Expand All @@ -163,6 +157,18 @@ public List<UserSubjectAssignment> assignSubjects(User user, List<Individual> su
}
}

private void validateAndCreateUpdateUserSubjectAssignment(boolean assignmentVoided, User user, Individual subject,
List<UserSubjectAssignment> userSubjectAssignmentList,
List<Long> addressLevels, List<String> errors) {
try {
checkIfSubjectLiesWithinUserCatchment(assignmentVoided, subject, addressLevels);
checkIfSubjectIsPartOfGroupAssignedToUser(assignmentVoided, user, subject);
createUpdateAssignment(assignmentVoided, userSubjectAssignmentList, user, subject);
} catch (Exception ve) {
errors.add(ve.getMessage());
}
}

private void checkIfSubjectIsPartOfGroupAssignedToUser(boolean assignmentVoided, User user, Individual subject) throws ValidationException {
if (assignmentVoided && !subject.getSubjectType().isGroup()) {
List<GroupSubject> groupSubjects = groupSubjectRepository.findAllByMemberSubjectAndIsVoidedFalse(subject);
Expand Down Expand Up @@ -212,7 +218,7 @@ private void onlyIfAssignGroupThenAssignMembersAlsoToUser(boolean assignmentVoid
if (!assignmentVoided && subject.getSubjectType().isGroup()) {
List<GroupSubject> groupSubjects = groupSubjectRepository.findAllByGroupSubjectAndIsVoidedFalse(subject);
for (GroupSubject groupSubject : groupSubjects) {
createUpdateAssignment(assignmentVoided, userSubjectAssignmentList, user, groupSubject.getMemberSubject());
createUpdateAssignment(false, userSubjectAssignmentList, user, groupSubject.getMemberSubject());
}
}
}
Expand Down

0 comments on commit 39c0469

Please sign in to comment.