Skip to content

Commit

Permalink
GRAD2-2464
Browse files Browse the repository at this point in the history
Backend changes for Optional Program CRUD
  • Loading branch information
arybakov-cgi committed Jan 30, 2024
1 parent 3f4c000 commit 3eebf76
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,10 @@ public ResponseEntity<List<UUID>> getDeceasedStudentIDs(@RequestBody List<UUID>
@PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT_OPTIONAL_PROGRAM)
@Operation(summary = "Create Student Optional Grad Program by Student ID", description = "Create Student Optional Grad Program by Student ID", tags = { "Optional Student Graduation Status" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<GraduationStudentRecord> createStudentGradOptionalProgram(@PathVariable UUID studentID, @RequestBody StudentOptionalProgram gradStudentOptionalProgram,
public ResponseEntity<GraduationStudentRecord> createStudentGradOptionalProgram(@PathVariable UUID studentID, @RequestBody StudentOptionalProgram gradStudentOptionalProgram, @RequestParam (value = "careerProgramCode", required = false) String careerProgramCode,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("Create student Optional Grad Program for Student ID: {}", studentID);
graduationStatusService.createStudentGradOptionalProgram(studentID, gradStudentOptionalProgram);
graduationStatusService.createStudentGradOptionalProgram(studentID, gradStudentOptionalProgram, careerProgramCode);
return response.GET(graduationStatusService.getGraduationStatus(studentID, accessToken.replace(BEARER, "")));
}

Expand All @@ -303,10 +303,10 @@ public ResponseEntity<GraduationStudentRecord> updateStudentGradOptionalProgram(
@PreAuthorize(PermissionsConstants.UPDATE_GRADUATION_STUDENT_OPTIONAL_PROGRAM)
@Operation(summary = "Delete Student Optional Grad Program by Student ID", description = "Delete Student Optional Grad Program by Student ID", tags = { "Optional Student Graduation Status" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public ResponseEntity<GraduationStudentRecord> deleteStudentGradOptionalProgram(@PathVariable UUID studentID, @PathVariable UUID optionalProgramID, @RequestParam (value = "careerProgramID", required = false) String careerProgramID,
public ResponseEntity<GraduationStudentRecord> deleteStudentGradOptionalProgram(@PathVariable UUID studentID, @PathVariable UUID optionalProgramID, @RequestParam (value = "careerProgramCode", required = false) String careerProgramCode,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("Delete student Optional Program for Student ID: {}", studentID);
graduationStatusService.deleteStudentGradOptionalProgram(studentID, optionalProgramID, careerProgramID);
graduationStatusService.deleteStudentGradOptionalProgram(studentID, optionalProgramID, careerProgramCode);
return response.GET(graduationStatusService.getGraduationStatus(studentID, accessToken.replace(BEARER, "")));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package ca.bc.gov.educ.api.gradstudent.model.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.GenericGenerator;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.util.UUID;

@Data
Expand All @@ -16,6 +14,11 @@
public class StudentCareerProgramEntity extends BaseEntity {

@Id
@GeneratedValue(generator = "UUID")
@GenericGenerator(
name = "UUID",
strategy = "org.hibernate.id.UUIDGenerator"
)
@Column(name = "STUDENT_CAREER_PROGRAM_ID", nullable = false)
private UUID id;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface StudentCareerProgramRepository extends JpaRepository<StudentCar

void deleteByStudentID(UUID studentID);

void deleteStudentCareerProgramEntityByStudentIDAndId(UUID studentGuid, UUID id);
void deleteStudentCareerProgramEntityByStudentIDAndCareerProgramCode(UUID studentGuid, String careerProgramCode);
}
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ public StudentOptionalProgram saveStudentGradOptionalProgram(StudentOptionalProg
}

@Transactional
public StudentOptionalProgram createStudentGradOptionalProgram(UUID studentID, StudentOptionalProgram gradStudentOptionalProgram) throws EntityNotFoundException {
public StudentOptionalProgram createStudentGradOptionalProgram(UUID studentID, StudentOptionalProgram gradStudentOptionalProgram, String careerProgramCode) throws EntityNotFoundException {
gradStudentOptionalProgram.setStudentID(studentID);
validateStudent(getGraduationStatus(studentID));
StudentOptionalProgramEntity sourceObject = gradStudentOptionalProgramTransformer.transformToEntity(gradStudentOptionalProgram);
Expand All @@ -800,6 +800,12 @@ public StudentOptionalProgram createStudentGradOptionalProgram(UUID studentID, S
BeanUtils.copyProperties(sourceObject, gradEnity, CREATE_USER, CREATE_DATE);
gradEnity.setOptionalProgramCompletionDate(sourceObject.getOptionalProgramCompletionDate());
StudentOptionalProgramEntity gradEnitySaved = gradStudentOptionalProgramRepository.save(gradEnity);
if(StringUtils.equalsIgnoreCase(careerProgramCode, "CP")) {
StudentCareerProgramEntity studentCareerProgramEntity = new StudentCareerProgramEntity();
studentCareerProgramEntity.setStudentID(studentID);
studentCareerProgramEntity.setCareerProgramCode(careerProgramCode);
gradStudentCareerProgramRepository.save(studentCareerProgramEntity);
}
historyService.createStudentOptionalProgramHistory(gradEnitySaved, USER_CREATE);
graduationStatusRepository.updateGradStudentRecalculationFlags(studentID, "Y", "Y");
return gradStudentOptionalProgramTransformer.transformToDTO(gradEnitySaved);
Expand Down Expand Up @@ -830,7 +836,7 @@ public StudentOptionalProgram updateStudentGradOptionalProgram(UUID studentID, U
}

@Transactional
public void deleteStudentGradOptionalProgram(UUID studentID, UUID optionalProgramID, String careerProgramID) throws EntityNotFoundException {
public void deleteStudentGradOptionalProgram(UUID studentID, UUID optionalProgramID, String careerProgramCode) throws EntityNotFoundException {
validateStudent(getGraduationStatus(studentID));
Optional<StudentOptionalProgramEntity> gradStudentOptionalOptional =
gradStudentOptionalProgramRepository.findByStudentIDAndOptionalProgramID(studentID, optionalProgramID);
Expand All @@ -840,8 +846,8 @@ public void deleteStudentGradOptionalProgram(UUID studentID, UUID optionalProgra
logger.debug(" -> Student Optional Program Entity is found for ID: {} === Entity ID: {}", optionalProgramID, optionalProgramID);
gradStudentOptionalProgramRepository.delete(gradEnity);
historyService.createStudentOptionalProgramHistory(gradEnity, USER_DELETE);
if(StringUtils.isNotBlank(careerProgramID)) {
gradStudentCareerProgramRepository.deleteStudentCareerProgramEntityByStudentIDAndId(studentID, UUID.fromString(careerProgramID));
if(StringUtils.isNotBlank(careerProgramCode)) {
gradStudentCareerProgramRepository.deleteStudentCareerProgramEntityByStudentIDAndCareerProgramCode(studentID, careerProgramCode);
}
graduationStatusRepository.updateGradStudentRecalculationFlags(studentID, "Y", "Y");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,13 @@ public void testCreateStudentGradOptionalProgram() {
BeanUtils.copyProperties(gradStudentOptionalProgramEntity, studentOptionalProgram);
studentOptionalProgram.setOptionalProgramCompletionDate(EducGradStudentApiUtils.formatDate(gradStudentOptionalProgramEntity.getOptionalProgramCompletionDate(), "yyyy-MM-dd" ));

Mockito.when(graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram)).thenReturn(studentOptionalProgram);
Mockito.when(graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP")).thenReturn(studentOptionalProgram);
Mockito.when(graduationStatusService.getGraduationStatus(studentID, "accessToken")).thenReturn(graduationStudentRecord);

Mockito.when(responseHelper.GET(graduationStudentRecord)).thenReturn(ResponseEntity.ok().body(graduationStudentRecord));

var result = commonController.createStudentGradOptionalProgram(studentID, studentOptionalProgram,"accessToken");
Mockito.verify(graduationStatusService).createStudentGradOptionalProgram(studentID, studentOptionalProgram);
var result = commonController.createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP", "accessToken");
Mockito.verify(graduationStatusService).createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP");
assertThat(result).isNotNull();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ public void testCreateCRUDStudentGradOptionalProgram() {
doNothing().when(historyService).createStudentOptionalProgramHistory(gradStudentOptionalProgramEntity, "USER_CREATE");
doNothing().when(graduationStatusRepository).updateGradStudentRecalculationFlags(studentID, "Y", "Y");

var result = graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram);
var result = graduationStatusService.createStudentGradOptionalProgram(studentID, studentOptionalProgram, "CP");

assertThat(result).isNotNull();

Expand Down

0 comments on commit 3eebf76

Please sign in to comment.