diff --git a/avni-server-api/src/main/java/org/avni/server/service/UserSubjectAssignmentService.java b/avni-server-api/src/main/java/org/avni/server/service/UserSubjectAssignmentService.java index ebbad760e..c200a8d75 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/UserSubjectAssignmentService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/UserSubjectAssignmentService.java @@ -147,13 +147,7 @@ public List assignSubjects(User user, List su List listOfSubjects = subjectTypeList.getValue(); List 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()) { @@ -163,6 +157,18 @@ public List assignSubjects(User user, List su } } + private void validateAndCreateUpdateUserSubjectAssignment(boolean assignmentVoided, User user, Individual subject, + List userSubjectAssignmentList, + List addressLevels, List 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 groupSubjects = groupSubjectRepository.findAllByMemberSubjectAndIsVoidedFalse(subject); @@ -212,7 +218,7 @@ private void onlyIfAssignGroupThenAssignMembersAlsoToUser(boolean assignmentVoid if (!assignmentVoided && subject.getSubjectType().isGroup()) { List groupSubjects = groupSubjectRepository.findAllByGroupSubjectAndIsVoidedFalse(subject); for (GroupSubject groupSubject : groupSubjects) { - createUpdateAssignment(assignmentVoided, userSubjectAssignmentList, user, groupSubject.getMemberSubject()); + createUpdateAssignment(false, userSubjectAssignmentList, user, groupSubject.getMemberSubject()); } } }