Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 3531f66

Browse files
Merge pull request #189 from sef-global/development
ScholarX v1.3
2 parents 19a38ca + 46ec654 commit 3531f66

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/main/java/org/sefglobal/scholarx/repository/MenteeRepository.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public interface MenteeRepository extends JpaRepository<Mentee, Long> {
2121

2222
List<Mentee> findAllByProgramIdAndProfileId(long programId, long profileId);
2323

24+
List<Mentee> findAllByProgramIdAndProfileIdAndState(long programId, long profileId, EnrolmentState state);
25+
2426
List<Mentee> findAllByProgramIdAndProfileIdAndStateIn(long programId, long profileId, List<EnrolmentState> states);
2527

2628
Optional<Mentee> findByProfileIdAndMentorId(long profileId, long mentorId);
@@ -29,6 +31,8 @@ public interface MenteeRepository extends JpaRepository<Mentee, Long> {
2931

3032
List<Mentee> findAllByProgramId(long id);
3133

34+
List<Mentee> findAllByProgramIdAndState(long programId, EnrolmentState state);
35+
3236
@Modifying
3337
@Query(
3438
value = "DELETE " +
@@ -52,4 +56,16 @@ public interface MenteeRepository extends JpaRepository<Mentee, Long> {
5256
nativeQuery = true
5357
)
5458
void removeAllByProgramIdAndProfileIdAndMentorIdNot(long programId, long profileId, long mentorId);
59+
60+
@Modifying
61+
@Query(
62+
value = "UPDATE " +
63+
"mentee " +
64+
"SET state = 'REMOVED' " +
65+
"WHERE profile_id = :profileId " +
66+
"AND program_id = :programId ",
67+
nativeQuery = true
68+
)
69+
void removeAllByProgramIdAndProfileId(long programId, long profileId);
70+
5571
}

src/main/java/org/sefglobal/scholarx/service/ProgramService.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ public Program updateState(long id) throws ResourceNotFoundException {
152152
}
153153

154154
ProgramState nextState = program.get().getState().next();
155+
if (ProgramState.ONGOING.equals(nextState)) {
156+
List<Mentee> approvedMenteeList = menteeRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED);
157+
for (Mentee mentee : approvedMenteeList) {
158+
long profileId = mentee.getProfile().getId();
159+
if (menteeRepository.findAllByProgramIdAndProfileIdAndState(id, profileId, EnrolmentState.APPROVED).size() != 1) {
160+
menteeRepository.removeAllByProgramIdAndProfileId(id, profileId);
161+
}
162+
}
163+
}
155164
program.get().setState(nextState);
156165
return programRepository.save(program.get());
157166
}

0 commit comments

Comments
 (0)