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

4.8.11 sonar fixes #518

Open
wants to merge 17 commits into
base: 4.8.12-dev-v2
Choose a base branch
from
Open
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 @@ -110,19 +110,18 @@ public ResponseEntity<Map<String, Object>> getUserAssessmentByContent(@RequestHe
*/
@GetMapping("/v2/{courseId}/assessment/{assessmentContentId}")
public ResponseEntity<Map<String, Object>> getAssessmentContent(@PathVariable("courseId") String courseId,
@PathVariable("assessmentContentId") String assessmentContentId, @RequestHeader("rootOrg") String rootOrg)
throws Exception {
@PathVariable("assessmentContentId") String assessmentContentId, @RequestHeader("rootOrg") String rootOrg) {
return new ResponseEntity<>(assessmentService.getAssessmentContent(courseId, assessmentContentId),
HttpStatus.OK);
}

// =======================
// QUML based Assessment APIs
@PostMapping("/v3/user/assessment/submit")
public ResponseEntity<?> submitUserAssessmentV3(@Valid @RequestBody Map<String, Object> requestBody,
public ResponseEntity<SBApiResponse> submitUserAssessmentV3(@Valid @RequestBody Map<String, Object> requestBody,
@RequestHeader("x-authenticated-user-token") String authUserToken , @RequestParam(name = "editMode" ,required = false) String editMode) throws Exception {

Boolean edit = StringUtils.isEmpty(editMode) ? false : Boolean.parseBoolean(editMode);
Boolean edit = StringUtils.isEmpty(editMode) ? Boolean.FALSE : Boolean.parseBoolean(editMode);
SBApiResponse submitResponse = assessmentServiceV2.submitAssessment(requestBody, authUserToken,edit);
return new ResponseEntity<>(submitResponse, submitResponse.getResponseCode());
}
Expand All @@ -144,16 +143,16 @@ public ResponseEntity<SBApiResponse> readAssessment(
}

@PostMapping("/v1/quml/question/list")
public ResponseEntity<?> readQuestionList(@Valid @RequestBody Map<String, Object> requestBody,
@RequestHeader("x-authenticated-user-token") String authUserToken) throws Exception {
public ResponseEntity<SBApiResponse> readQuestionList(@Valid @RequestBody Map<String, Object> requestBody,
@RequestHeader("x-authenticated-user-token") String authUserToken) {
SBApiResponse response = assessmentServiceV2.readQuestionList(requestBody, authUserToken);
return new ResponseEntity<>(response, response.getResponseCode());
}

@GetMapping("/v1/quml/assessment/retake/{assessmentIdentifier}")
public ResponseEntity<SBApiResponse> retakeAssessment(
@PathVariable("assessmentIdentifier") String assessmentIdentifier,
@RequestHeader(Constants.X_AUTH_TOKEN) String token) throws Exception {
@RequestHeader(Constants.X_AUTH_TOKEN) String token) {
SBApiResponse readResponse = assessmentServiceV2.retakeAssessment(assessmentIdentifier, token);
return new ResponseEntity<>(readResponse, readResponse.getResponseCode());
}
Expand All @@ -163,9 +162,9 @@ public ResponseEntity<SBApiResponse> retakeAssessment(
// Async capability and not using Redis
// =======================
@PostMapping("/v4/user/assessment/submit")
public ResponseEntity<?> submitUserAssessmentV4(@Valid @RequestBody Map<String, Object> requestBody,
public ResponseEntity<SBApiResponse> submitUserAssessmentV4(@Valid @RequestBody Map<String, Object> requestBody,
@RequestHeader("x-authenticated-user-token") String authUserToken,@RequestParam(name = "editMode" ,required = false) String editMode) {
Boolean edit = StringUtils.isEmpty(editMode) ? false : Boolean.parseBoolean(editMode);
Boolean edit = StringUtils.isEmpty(editMode) ? Boolean.FALSE : Boolean.parseBoolean(editMode);
SBApiResponse submitResponse = assessmentServiceV4.submitAssessmentAsync(requestBody, authUserToken,edit);
return new ResponseEntity<>(submitResponse, submitResponse.getResponseCode());
}
Expand All @@ -182,15 +181,15 @@ public ResponseEntity<?> submitUserAssessmentV4(@Valid @RequestBody Map<String,
public ResponseEntity<SBApiResponse> readAssessmentV4(
@PathVariable("assessmentIdentifier") String assessmentIdentifier,
@RequestHeader(Constants.X_AUTH_TOKEN) String token,@RequestParam(name = "editMode" ,required = false) String editMode) {
Boolean edit = StringUtils.isEmpty(editMode) ? false : Boolean.parseBoolean(editMode);
Boolean edit = StringUtils.isEmpty(editMode) ? Boolean.FALSE: Boolean.parseBoolean(editMode);
SBApiResponse readResponse = assessmentServiceV4.readAssessment(assessmentIdentifier, token,edit);
return new ResponseEntity<>(readResponse, readResponse.getResponseCode());
}

@PostMapping("/v4/quml/question/list")
public ResponseEntity<?> readQuestionListV4(@Valid @RequestBody Map<String, Object> requestBody,
public ResponseEntity<SBApiResponse> readQuestionListV4(@Valid @RequestBody Map<String, Object> requestBody,
@RequestHeader("x-authenticated-user-token") String authUserToken,@RequestParam(name = "editMode" ,required = false) String editMode) {
Boolean edit = StringUtils.isEmpty(editMode) ? false : Boolean.parseBoolean(editMode);
Boolean edit = StringUtils.isEmpty(editMode) ? Boolean.FALSE: Boolean.parseBoolean(editMode);
SBApiResponse response = assessmentServiceV4.readQuestionList(requestBody, authUserToken,edit);
return new ResponseEntity<>(response, response.getResponseCode());
}
Expand All @@ -199,13 +198,13 @@ public ResponseEntity<?> readQuestionListV4(@Valid @RequestBody Map<String, Obje
public ResponseEntity<SBApiResponse> retakeAssessmentV4(
@PathVariable("assessmentIdentifier") String assessmentIdentifier,
@RequestHeader(Constants.X_AUTH_TOKEN) String token,@RequestParam(name = "editMode" ,required = false) String editMode) {
Boolean edit = StringUtils.isEmpty(editMode) ? false : Boolean.parseBoolean(editMode);
Boolean edit = StringUtils.isEmpty(editMode) ? Boolean.FALSE: Boolean.parseBoolean(editMode);
SBApiResponse readResponse = assessmentServiceV4.retakeAssessment(assessmentIdentifier, token,edit);
return new ResponseEntity<>(readResponse, readResponse.getResponseCode());
}

@PostMapping("/v4/quml/assessment/result")
public ResponseEntity<?> readAssessmentResultV4(@Valid @RequestBody Map<String, Object> requestBody,
public ResponseEntity<SBApiResponse> readAssessmentResultV4(@Valid @RequestBody Map<String, Object> requestBody,
@RequestHeader("x-authenticated-user-token") String authUserToken) {
SBApiResponse response = assessmentServiceV4.readAssessmentResultV4(requestBody, authUserToken);
return new ResponseEntity<>(response, response.getResponseCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.springframework.web.bind.annotation.RestController;
import org.sunbird.assessment.repo.CohortUsers;
import org.sunbird.assessment.service.CohortsService;
import org.sunbird.common.model.Response;
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.common.util.Constants;

Expand All @@ -35,7 +34,7 @@ public class CohortsController {
@GetMapping("/v2/resources/{resourceId}/user/{userUUID}/cohorts/top-performers")
public ResponseEntity<List<CohortUsers>> getTopPerformers(@PathVariable("resourceId") String resourceId,
@RequestHeader("rootOrg") String rootOrg, @PathVariable("userUUID") String userUUID,
@RequestParam(value = "count", defaultValue = "20", required = false) Integer count) throws Exception {
@RequestParam(value = "count", defaultValue = "20", required = false) Integer count) {

return new ResponseEntity<>(cohortsServ.getTopPerformers(rootOrg, resourceId, userUUID, count),
HttpStatus.OK);
Expand All @@ -56,8 +55,7 @@ public ResponseEntity<List<CohortUsers>> getActiveUsers(@RequestHeader("Authoriz
@PathVariable("resourceId") String contentId, @RequestHeader("rootOrg") String rootOrg,
@PathVariable("userUUID") String userUUID,
@RequestParam(value = "count", required = false, defaultValue = "50") Integer count,
@RequestParam(value = "filter", required = false, defaultValue = "false") Boolean toFilter)
throws Exception {
@RequestParam(value = "filter", required = false, defaultValue = "false") Boolean toFilter) {
if (authUserToken.contains(" ")) {
authUserToken = authUserToken.split(" ")[1];
}
Expand All @@ -80,7 +78,7 @@ public ResponseEntity<SBApiResponse> autoEnrollmentInCourse(@RequestHeader("Auth
@RequestHeader(name = Constants.X_AUTH_USER_ORG_ID, required = false) String rootOrgId,
@PathVariable("courseId") String contentId,
@RequestHeader("rootOrg") String rootOrg,
@PathVariable("userUUID") String userUUID) throws Exception {
@PathVariable("userUUID") String userUUID) {
if (authUserToken.contains(" ")) {
authUserToken = authUserToken.split(" ")[1];
}
Expand All @@ -103,7 +101,7 @@ public ResponseEntity<SBApiResponse> autoEnrollmentInCourse(@RequestHeader("Auth
@GetMapping("/v2/resources/user/cohorts/top-performers")
public ResponseEntity<List<CohortUsers>> getTopPerformersForResource(@RequestHeader("resourceId") String resourceId,
@RequestHeader("rootOrg") String rootOrg, @RequestHeader("userUUID") String userUUID,
@RequestParam(value = "count", defaultValue = "20", required = false) Integer count) throws Exception {
@RequestParam(value = "count", defaultValue = "20", required = false) Integer count) {

return new ResponseEntity<>(cohortsServ.getTopPerformers(rootOrg, resourceId, userUUID, count),
HttpStatus.OK);
Expand All @@ -127,8 +125,7 @@ public ResponseEntity<List<CohortUsers>> getActiveUsersForResource(@RequestHeade
@RequestHeader("resourceId") String contentId, @RequestHeader("rootOrg") String rootOrg,
@RequestHeader("userUUID") String userUUID,
@RequestParam(value = "count", required = false, defaultValue = "50") Integer count,
@RequestParam(value = "filter", required = false, defaultValue = "false") Boolean toFilter)
throws Exception {
@RequestParam(value = "filter", required = false, defaultValue = "false") Boolean toFilter) {
return new ResponseEntity<>(
cohortsServ.getActiveUsers(authUserToken, rootOrgId, rootOrg, contentId, userUUID, count, toFilter),
HttpStatus.OK);
Expand All @@ -148,7 +145,7 @@ public ResponseEntity<SBApiResponse> userAutoEnrollment(@RequestHeader("x-authen
@RequestHeader(name = Constants.X_AUTH_USER_ORG_ID, required = false) String rootOrgId,
@RequestHeader("courseId") String contentId,
@RequestHeader("rootOrg") String rootOrg,
@RequestHeader("userUUID") String userUUID)throws Exception {
@RequestHeader("userUUID") String userUUID) {

SBApiResponse response = cohortsServ.autoEnrollmentInCourseV2(authUserToken, rootOrgId, rootOrg, contentId, userUUID);
return new ResponseEntity<>(response, response.getResponseCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class OffensiveDataReportController {

@PostMapping("/v1/offensive/data/flag")
public ResponseEntity<SBApiResponse> createFlag(
@Valid @RequestBody Map<String, Object> requestBody, @RequestHeader(Constants.X_AUTH_TOKEN) String token) throws Exception {
@Valid @RequestBody Map<String, Object> requestBody, @RequestHeader(Constants.X_AUTH_TOKEN) String token) {
SBApiResponse readResponse = offensiveDataFlagService.createFlag(requestBody, token);
return new ResponseEntity<>(readResponse, readResponse.getResponseCode());
}
Expand All @@ -31,7 +31,7 @@ public ResponseEntity<SBApiResponse> updateFlag(@RequestHeader(Constants.X_AUTH_
}

@GetMapping("/v1/offensive/data/flag/getFlaggedData")
public ResponseEntity<SBApiResponse> getFlaggedData(@RequestHeader(Constants.X_AUTH_TOKEN) String token) throws Exception {
public ResponseEntity<SBApiResponse> getFlaggedData(@RequestHeader(Constants.X_AUTH_TOKEN) String token) {
SBApiResponse readResponse = offensiveDataFlagService.getFlaggedData(token);
return new ResponseEntity<>(readResponse, readResponse.getResponseCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public Map<String, Object> insertQuizOrAssessment(Map<String, Object> persist, B
* @return
* @throws Exception
*/
public List<Map<String, Object>> getAssessmentbyContentUser(String rootOrg, String courseId, String userId)
throws Exception;
public List<Map<String, Object>> getAssessmentbyContentUser(String rootOrg, String courseId, String userId);

List<Map<String, Object>> fetchUserAssessmentDataFromDB(String userId, String assessmentIdentifier);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
Expand All @@ -17,8 +18,6 @@
import org.sunbird.cassandra.utils.CassandraOperation;
import org.sunbird.common.model.SBApiResponse;
import org.sunbird.common.util.Constants;
import org.sunbird.core.logger.CbExtLogger;

import com.datastax.driver.core.utils.UUIDs;
import com.google.gson.Gson;

Expand All @@ -29,7 +28,6 @@ public class AssessmentRepositoryImpl implements AssessmentRepository {
public static final String RESULT = "result";
public static final String SOURCE_ID = "sourceId";
public static final String USER_ID = "userId";
private CbExtLogger logger = new CbExtLogger(getClass().getName());

@Autowired
UserAssessmentSummaryRepository userAssessmentSummaryRepo;
Expand All @@ -46,15 +44,15 @@ public class AssessmentRepositoryImpl implements AssessmentRepository {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

@Override
public Map<String, Object> getAssessmentAnswerKey(String artifactUrl) throws Exception {
// TODO Auto-generated method stub
return null;
public Map<String, Object> getAssessmentAnswerKey(String artifactUrl) {

return new HashMap<>();
}

@Override
public Map<String, Object> getQuizAnswerKey(AssessmentSubmissionDTO quizMap) throws Exception {
// TODO Auto-generated method stub
return null;
public Map<String, Object> getQuizAnswerKey(AssessmentSubmissionDTO quizMap) {

return new HashMap<>();
}

@Override
Expand All @@ -65,15 +63,8 @@ public Map<String, Object> insertQuizOrAssessment(Map<String, Object> persist, B

// insert assessment and assessment summary
if (Boolean.TRUE.equals(isAssessment)) {
UserAssessmentMasterModel assessment = new UserAssessmentMasterModel(
new UserAssessmentMasterPrimaryKeyModel(persist.get(ROOT_ORG).toString(), date,
persist.get("parent").toString(), BigDecimal.valueOf((Double) persist.get(RESULT)),
UUIDs.timeBased()),
Integer.parseInt(persist.get("correct").toString()), formatter.parse(formatter.format(date)),
Integer.parseInt(persist.get("incorrect").toString()),
Integer.parseInt(persist.get("blank").toString()), persist.get("parentContentType").toString(),
new BigDecimal(60), persist.get(SOURCE_ID).toString(), persist.get("title").toString(),
persist.get(USER_ID).toString());
Map<String, Object> userAssessmentMasterModelDate = this.getUserAssessmentMasterModelData(persist, date);
UserAssessmentMasterModel assessment = new UserAssessmentMasterModel();
UserAssessmentSummaryModel summary = new UserAssessmentSummaryModel();
UserAssessmentSummaryModel data = userAssessmentSummaryRepo
.findById(new UserAssessmentSummaryPrimaryKeyModel(persist.get(ROOT_ORG).toString(),
Expand Down Expand Up @@ -129,9 +120,7 @@ public Map<String, Object> insertQuizOrAssessment(Map<String, Object> persist, B
}

@Override
public List<Map<String, Object>> getAssessmentbyContentUser(String rootOrg, String courseId, String userId)
throws Exception {
// TODO Auto-generated method stub
public List<Map<String, Object>> getAssessmentbyContentUser(String rootOrg, String courseId, String userId) {
return Collections.emptyList();
}

Expand All @@ -155,9 +144,8 @@ public List<Map<String, Object>> fetchUserAssessmentDataFromDB(String userId, St
Map<String, Object> request = new HashMap<>();
request.put(Constants.USER_ID, userId);
request.put(Constants.ASSESSMENT_ID_KEY, assessmentIdentifier);
List<Map<String, Object>> existingDataList = cassandraOperation.getRecordsByProperties(
return cassandraOperation.getRecordsByProperties(
Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER_ASSESSMENT_DATA, request, null);
return existingDataList;
}

@Override
Expand All @@ -182,4 +170,21 @@ public Boolean updateUserAssesmentDataToDB(String userId, String assessmentIdent
fieldsToBeUpdated, compositeKeys);
return true;
}


private Map<String, Object> getUserAssessmentMasterModelData(Map<String, Object> persist, Date date) throws ParseException {
Map<String, Object> userAssessmentMasterModelData = new HashMap<>();
userAssessmentMasterModelData.put("primaryKey", new UserAssessmentMasterPrimaryKeyModel(persist.get(ROOT_ORG).toString(), date,
persist.get("parent").toString(), BigDecimal.valueOf((Double) persist.get(RESULT)), UUIDs.timeBased()));
userAssessmentMasterModelData.put(Constants.CORRECT_COUNT, Integer.parseInt(persist.get(Constants.CORRECT).toString()));
userAssessmentMasterModelData.put(Constants.DATE_CREATED_ON, formatter.parse(formatter.format(date)));
userAssessmentMasterModelData.put(Constants.INCORRECT_COUNT, Integer.parseInt(persist.get(Constants.INCORRECT).toString()));
userAssessmentMasterModelData.put(Constants.NOT_ANSWERED_COUNT, Integer.parseInt(persist.get(Constants.BLANK).toString()));
userAssessmentMasterModelData.put(Constants.PARENT_CONTENT_TYPE, persist.get(Constants.PARENT_CONTENT_TYPE).toString());
userAssessmentMasterModelData.put(Constants.PASS_PERCENTAGE, new BigDecimal(60));
userAssessmentMasterModelData.put(Constants.SOURCE_ID, persist.get(SOURCE_ID).toString());
userAssessmentMasterModelData.put(Constants.SOURCE_TITLE, persist.get(Constants.TITLE).toString());
userAssessmentMasterModelData.put(Constants.USER_ID, persist.get(USER_ID).toString());
return userAssessmentMasterModelData;
}
}
40 changes: 20 additions & 20 deletions src/main/java/org/sunbird/assessment/repo/CohortUsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

@JsonIgnoreProperties(ignoreUnknown = true)
public class CohortUsers {
private String first_name;
private String last_name;
private String firstName;
private String lastName;
private String email;
private String desc;
private String user_id;
private String userId;
private String department;
private String phone_No;
private String phoneNo;
private String designation;
private String userLocation;
private String city;
Expand All @@ -21,20 +21,20 @@ public String getDesc() {
public void setDesc(String desc) {
this.desc = desc;
}
public String getFirst_name() {
return first_name;
public String getFirstName() {
return firstName;
}

public void setFirst_name(String first_name) {
this.first_name = first_name;
public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLast_name() {
return last_name;
public String getLastName() {
return lastName;
}

public void setLast_name(String last_name) {
this.last_name = last_name;
public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getEmail() {
Expand All @@ -45,12 +45,12 @@ public void setEmail(String email) {
this.email = email;
}

public String getUser_id() {
return user_id;
public String getUserId() {
return userId;
}

public void setUser_id(String user_id) {
this.user_id = user_id;
public void setUserId(String userId) {
this.userId = userId;
}

public String getDesignation() {
Expand All @@ -69,12 +69,12 @@ public void setDepartment(String department) {
this.department = department;
}

public String getPhone_No() {
return phone_No;
public String getPhoneNo() {
return phoneNo;
}

public void setPhone_No(String phone_No) {
this.phone_No = phone_No;
public void setPhoneNo(String phoneNo) {
this.phoneNo = phoneNo;
}

public String getUserLocation() {
Expand Down
Loading