Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sonar fixes. #740

Draft
wants to merge 1 commit into
base: grad-release
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
Expand All @@ -29,26 +29,22 @@
@RestController
@RequestMapping(EducGradStudentApiConstants.GRAD_STUDENT_API_ROOT_MAPPING)
@OpenAPIDefinition(info = @Info(title = "API for Common endpoints.", description = "This API is for Reading Common endpoints.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_STUDENT_UNGRAD_REASONS_DATA","READ_GRAD_STUDENT_CAREER_DATA"})})
@AllArgsConstructor
public class CommonController {

private static final Logger logger = LoggerFactory.getLogger(CommonController.class);

private static final String STATUS_CODE = "Status Code";
private static final String BEARER = "Bearer ";

@Autowired
CommonService commonService;

@Autowired
GradStudentReportService gradStudentReportService;

@Autowired
GraduationStatusService graduationStatusService;

@Autowired
GradValidation validation;

@Autowired
ResponseHelper response;

@GetMapping(EducGradStudentApiConstants.GET_STUDENT_CAREER_PROGRAM_BY_CAREER_PROGRAM_CODE_MAPPING)
Expand All @@ -67,7 +63,7 @@ public ResponseEntity<Boolean> getStudentCareerProgram(@PathVariable String cpCo
public ResponseEntity<List<StudentCareerProgram>> getAllStudentCareerProgramsList(@PathVariable String studentID,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("getAllStudentCareerProgramsList : ");
return response.GET(commonService.getAllGradStudentCareerProgramList(studentID,accessToken.replace("Bearer ", "")));
return response.GET(commonService.getAllGradStudentCareerProgramList(studentID,accessToken.replace(BEARER, "")));
}

@GetMapping(EducGradStudentApiConstants.GET_ALL_STUDENT_NOTES_MAPPING)
Expand Down Expand Up @@ -178,7 +174,7 @@ public ResponseEntity<Void> deleteStudentStatusCodes(@Valid @PathVariable String
public ResponseEntity<GradStudentAlgorithmData> getStudentGradStatusForAlgorithm(@PathVariable String studentID,
@RequestHeader(name="Authorization") String accessToken) {
logger.debug("Get Student Grad Status for studentID");
return response.GET(commonService.getGradStudentAlgorithmData(studentID,accessToken.replace("Bearer ", "")));
return response.GET(commonService.getGradStudentAlgorithmData(studentID,accessToken.replace(BEARER, "")));
}

@GetMapping(EducGradStudentApiConstants.GET_ALL_HISTORY_ACTIVITY_MAPPING)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
Expand All @@ -25,18 +25,16 @@
@RestController
@RequestMapping(EducGradStudentApiConstants.GRAD_STUDENT_API_ROOT_MAPPING)
@OpenAPIDefinition(info = @Info(title = "API for Grad Student Status.", description = "This API is for Grad Student Status.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_STUDENT_DATA", "UPDATE_GRAD_GRADUATION_STATUS"})})
@AllArgsConstructor
public class DataConversionController {

private static final Logger logger = LoggerFactory.getLogger(DataConversionController.class);
private static final String BEARER = "Bearer ";

@Autowired
DataConversionService dataConversionService;

@Autowired
GradValidation validation;

@Autowired
ResponseHelper response;

@PostMapping(EducGradStudentApiConstants.CONV_GRADUATION_STATUS_BY_STUDENT_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
Expand All @@ -23,17 +23,15 @@
@RestController
@RequestMapping(EducGradStudentApiConstants.GRAD_STUDENT_API_ROOT_MAPPING)
@OpenAPIDefinition(info = @Info(title = "API for Grad Status Snapshot for EDW.", description = "This API is for Grad Status Snapshot for EDW.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"READ_GRAD_STUDENT_DATA", "UPDATE_GRAD_GRADUATION_STATUS"})})
@AllArgsConstructor
public class EdwSnapshotController {

private static final Logger logger = LoggerFactory.getLogger(EdwSnapshotController.class);

@Autowired
EdwSnapshotService edwSnapshotService;

@Autowired
GradValidation validation;

@Autowired
ResponseHelper response;

@PostMapping(EducGradStudentApiConstants.EDW_GRADUATION_STATUS_SNAPSHOT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class GradStudentController {

@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(GradStudentController.class);
private static final String BEARER = "Bearer ";

private final GradStudentService gradStudentService;

Expand Down Expand Up @@ -56,7 +57,7 @@ public GradOnlyStudentSearch getGradStudentsFromStudentAPI(
.usualFirstName(usualFirstName).usualLastName(usualLastName).usualMiddleNames(usualMiddleNames)
.gender(gender).mincode(mincode).localID(localID).birthdateFrom(birthdateFrom).birthdateTo(birthdateTo)
.build();
return gradStudentService.getStudentFromStudentAPIGradOnly(studentSearchRequest,accessToken.replaceAll("Bearer ", ""));
return gradStudentService.getStudentFromStudentAPIGradOnly(studentSearchRequest,accessToken.replace(BEARER, ""));

}

Expand Down Expand Up @@ -93,15 +94,15 @@ public StudentSearch getGradNPenGradStudentFromStudentAPI(
@Operation(summary = "Search For Students by PEN", description = "Search for Student Demographics by PEN", tags = { "Student Demographics" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public List<GradSearchStudent> getGradStudentByPenFromStudentAPI(@PathVariable String pen, @RequestHeader(name="Authorization") String accessToken) {
return gradStudentService.getStudentByPenFromStudentAPI(pen,accessToken.replaceAll("Bearer ", ""));
return gradStudentService.getStudentByPenFromStudentAPI(pen,accessToken.replace(BEARER, ""));
}

@GetMapping(EducGradStudentApiConstants.GRAD_STUDENT_BY_STUDENT_ID_STUDENT_API)
@PreAuthorize("hasAuthority('SCOPE_READ_GRAD_STUDENT_DATA')")
@Operation(summary = "GET Student by STUDENT ID", description = "Get Student Demographics by Student ID", tags = { "Student Demographics" })
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "OK")})
public GradSearchStudent getGradStudentByStudentIDFromStudentAPI(@PathVariable String studentID, @RequestHeader(name="Authorization") String accessToken) {
return gradStudentService.getStudentByStudentIDFromStudentAPI(studentID,accessToken.replaceAll("Bearer ", ""));
return gradStudentService.getStudentByStudentIDFromStudentAPI(studentID,accessToken.replace(BEARER, ""));
}

@GetMapping(EducGradStudentApiConstants.GRAD_STUDENT_BY_STUDENT_ID_GRAD)
Expand All @@ -115,7 +116,7 @@ public GraduationStudentRecordDistribution getGradStudentByStudentIDFromGRAD(@Pa
@PostMapping
@PreAuthorize("hasAuthority('SCOPE_WRITE_STUDENT')")
public Student addNewPenFromStudentAPI(@Validated @RequestBody StudentCreate student, @RequestHeader(name="Authorization") String accessToken) {
return gradStudentService.addNewPenFromStudentAPI(student, accessToken.replaceAll("Bearer ", ""));
return gradStudentService.addNewPenFromStudentAPI(student, accessToken.replace(BEARER, ""));
}

@PostMapping (EducGradStudentApiConstants.GRAD_STUDENT_BY_SEARCH_CRITERIAS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -31,24 +31,20 @@
@RestController
@RequestMapping(EducGradStudentApiConstants.GRAD_STUDENT_API_ROOT_MAPPING)
@OpenAPIDefinition(info = @Info(title = "API for Grad Student Status.", description = "This API is for Grad Student Status.", version = "1"), security = {@SecurityRequirement(name = "OAUTH2", scopes = {"UPDATE_GRAD_GRADUATION_STATUS"})})
@AllArgsConstructor
public class GraduationStatusController {

private static final Logger logger = LoggerFactory.getLogger(GraduationStatusController.class);
private static final String BEARER = "Bearer ";

@Autowired
GraduationStatusService gradStatusService;

@Autowired
HistoryService historyService;

@Autowired
Publisher publisher;

@Autowired
GradValidation validation;

@Autowired
ResponseHelper response;

@GetMapping (EducGradStudentApiConstants.GRADUATION_STATUS_BY_STUDENT_ID)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ca.bc.gov.educ.api.gradstudent.repository;

import ca.bc.gov.educ.api.gradstudent.model.entity.HistoryActivityCodeEntity;
import ca.bc.gov.educ.api.gradstudent.model.entity.StudentStatusEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import ca.bc.gov.educ.api.gradstudent.repository.ReportGradSchoolYearEndRepository;
import ca.bc.gov.educ.api.gradstudent.repository.ReportGradStudentDataRepository;
import ca.bc.gov.educ.api.gradstudent.util.EducGradStudentApiConstants;
import lombok.AllArgsConstructor;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
Expand All @@ -26,19 +26,19 @@
import static ca.bc.gov.educ.api.gradstudent.service.GraduationStatusService.PAGE_SIZE;

@Service
@AllArgsConstructor
public class GradStudentReportService extends GradBaseService {

private static final Logger logger = LoggerFactory.getLogger(GradStudentReportService.class);

@Autowired
ReportGradStudentDataRepository reportGradStudentDataRepository;
@Autowired

ReportGradSchoolYearEndRepository reportGradSchoolYearEndRepository;
@Autowired

ReportGradStudentTransformer reportGradStudentTransformer;
@Autowired

EducGradStudentApiConstants constants;
@Autowired

WebClient webClient;

public List<ReportGradStudentData> getGradStudentDataBySchoolId(UUID schoolId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public GradOnlyStudentSearch getStudentFromStudentAPIGradOnly(StudentSearchReque
private List<GradSearchStudent> buildPartitions(List<Student> studentLists, String accessToken) {
List<GradSearchStudent> gradStudentList = new ArrayList<>();

List<UUID> studentIds = studentLists.stream().map(std -> UUID.fromString(std.getStudentID())).collect(Collectors.toList());
List<UUID> studentIds = studentLists.stream().map(std -> UUID.fromString(std.getStudentID())).toList();
int partitionSize = 1000;
List<List<UUID>> partitions = new LinkedList<>();
for (int i = 0; i < studentIds.size(); i += partitionSize) {
Expand Down Expand Up @@ -293,11 +293,6 @@ private void getSearchCriteria(String value, String value2, String paramterType,
if(criteria != null) criteriaList.add(criteria);
}

private GradSearchStudent populateGradStudent(GraduationStudentRecordEntity gradRecord, String accessToken) {
GradSearchStudent gradStu = new GradSearchStudent();
BeanUtils.copyProperties(gradRecord, gradStu);
return populateGradStudent(gradStu, accessToken);
}

private GradSearchStudent populateGradStudent(GraduationStudentRecordView gradRecord, String accessToken) {
GradSearchStudent gradStu = new GradSearchStudent();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package ca.bc.gov.educ.api.gradstudent;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class EducGradStudentApiApplicationTests {

//@Test
void contextLoads() {
/**
* Placeholder method
*/
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ public void testDeleteStudentStatus() {
public void testgetStudentGradStatusForAlgorithm() {

String studentID = new UUID(1,1).toString();
String accessToken = "accessToken";

GradSearchStudent gs = new GradSearchStudent();
gs.setStudentID(studentID);
Expand All @@ -329,7 +328,9 @@ public void testgetStudentGradStatusForAlgorithm() {
data.setGraduationStudentRecord(gsr);

Mockito.when(commonService.getGradStudentAlgorithmData(studentID,"accessToken")).thenReturn(data);
GradStudentAlgorithmData response = commonService.getGradStudentAlgorithmData(studentID,"accessToken");
commonController.getStudentGradStatusForAlgorithm(studentID, "accessToken");
assertThat(response).isNotNull();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public void testSaveStudentCareerProgram() {
UUID gradStudentCareerProgramID = UUID.randomUUID();
UUID studentID = UUID.randomUUID();
String careerProgramCode = "Test";
String pen = "123456789";

StudentCareerProgram studentCareerProgram = new StudentCareerProgram();
studentCareerProgram.setId(gradStudentCareerProgramID);
Expand Down Expand Up @@ -186,7 +185,7 @@ public void testDeleteStudentCareerProgram() {

Mockito.doNothing().when(dataConversionService).deleteStudentCareerProgram(careerProgramCode, studentID);
Mockito.when(responseHelper.DELETE(1)).thenReturn(new ResponseEntity<>(HttpStatus.NO_CONTENT));
var result = dataConversionController.deleteStudentCareerProgram(careerProgramCode.toString(), studentID.toString());
var result = dataConversionController.deleteStudentCareerProgram(careerProgramCode, studentID.toString());
Mockito.verify(dataConversionService).deleteStudentCareerProgram(careerProgramCode, studentID);
assertThat(result).isNotNull();
assertThat(result.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public void testGetGradStudentByPenFromStudentAPI() {
// ID
final UUID studentID = UUID.randomUUID();
final String pen = "123456789";
final String lastName = "LastName";
final String program = "2018-EN";
final String gradStatus = "A";
final String stdGrade = "12";
Expand Down Expand Up @@ -109,11 +108,7 @@ public void testAddNewPenFromStudentAPI() {
final String pen = "123456789";
final String firstName = "FirstName";
final String lastName = "LastName";
final String program = "2018-EN";
final String gradStatus = "A";
final String stdGrade = "12";
final String mincode = "12345678";
final String schoolName = "Test School";

// Grad Student
final StudentCreate student = new StudentCreate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,6 @@ public void testGetOptionalProgramStudentHistoryByID() {
@Test
public void testGetStudentHistoryByBatchID() {
// ID
String historyID = UUID.randomUUID().toString();
UUID studentID = UUID.randomUUID();
UUID schoolId = UUID.randomUUID();

Expand Down Expand Up @@ -664,7 +663,6 @@ public void testUpdateStudentFlagReadyForBatchJobByStudentIDs() {
UUID studentID = UUID.randomUUID();
UUID schoolId = UUID.randomUUID();
String batchJobType = "REGALG";
String mincode = "123456789";

StudentList stList = new StudentList();
stList.setStudentids(Arrays.asList(studentID));
Expand Down
Loading
Loading