Skip to content

Commit

Permalink
Assessment Feature Related Changes (#172)
Browse files Browse the repository at this point in the history
Assessment feature merging to Release branch
  • Loading branch information
juhiagl8 authored Feb 9, 2023
1 parent 97df821 commit 70a4e32
Show file tree
Hide file tree
Showing 10 changed files with 1,021 additions and 425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public ResponseEntity<?> readQuestionList(@Valid @RequestBody Map<String, Object
SBApiResponse response = assessmentServiceV2.readQuestionList(requestBody, authUserToken);
return new ResponseEntity<>(response, response.getResponseCode());
}
// QUML based Assessment APIs
// =======================

@GetMapping("/v1/quml/assessment/retake/{assessmentIdentifier}")
public ResponseEntity<SBApiResponse> retakeAssessment(
@PathVariable("assessmentIdentifier") String assessmentIdentifier,
@RequestHeader(Constants.X_AUTH_TOKEN) String token) throws Exception {
SBApiResponse readResponse = assessmentServiceV2.retakeAssessment(assessmentIdentifier, token);
return new ResponseEntity<>(readResponse, readResponse.getResponseCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface AssessmentRepository {

/**
* gets answer key for the assessment given the url
*
*
* @param artifactUrl
* @return
* @throws Exception
Expand All @@ -20,7 +20,7 @@ public interface AssessmentRepository {

/**
* gets answerkey for the quiz submission
*
*
* @param quizMap
* @return
* @throws Exception
Expand All @@ -29,7 +29,7 @@ public interface AssessmentRepository {

/**
* inserts quiz or assessments for a user
*
*
* @param persist
* @param isAssessment
* @return
Expand All @@ -40,7 +40,7 @@ public Map<String, Object> insertQuizOrAssessment(Map<String, Object> persist, B

/**
* gets assessment for a user given a content id
*
*
* @param courseId
* @param userId
* @return
Expand All @@ -49,7 +49,12 @@ public Map<String, Object> insertQuizOrAssessment(Map<String, Object> persist, B
public List<Map<String, Object>> getAssessmentbyContentUser(String rootOrg, String courseId, String userId)
throws Exception;

boolean addUserAssesmentStartTime(String userId, String assessmentIdentifier, Timestamp startTime);
List<Map<String, Object>> fetchUserAssessmentDataFromDB(String userId, String assessmentIdentifier);

Date fetchUserAssessmentStartTime(String userId, String s);
}
boolean addUserAssesmentDataToDB(String userId, String assessmentId, Timestamp startTime, Timestamp endTime,
Map<String, Object> questionSet, String status);

Boolean updateUserAssesmentDataToDB(String userId, String assessmentIdentifier,
Map<String, Object> submitAssessmentRequest, Map<String, Object> submitAssessmentResponse, String status,
Date startTime);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
package org.sunbird.assessment.repo;

import com.datastax.driver.core.utils.UUIDs;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.sunbird.assessment.dto.AssessmentSubmissionDTO;
Expand All @@ -9,10 +17,8 @@
import org.sunbird.common.util.Constants;
import org.sunbird.core.logger.CbExtLogger;

import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;
import com.datastax.driver.core.utils.UUIDs;
import com.google.gson.Gson;

@Service
public class AssessmentRepositoryImpl implements AssessmentRepository {
Expand All @@ -22,7 +28,7 @@ public class AssessmentRepositoryImpl implements AssessmentRepository {
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 Down Expand Up @@ -128,23 +134,50 @@ public List<Map<String, Object>> getAssessmentbyContentUser(String rootOrg, Stri
}

@Override
public boolean addUserAssesmentStartTime(String userId, String assessmentIdentifier, Timestamp startTime) {
public boolean addUserAssesmentDataToDB(String userId, String assessmentIdentifier, Timestamp startTime,
Timestamp endTime, Map<String, Object> questionSet, String status) {
Map<String, Object> request = new HashMap<>();
request.put(Constants.USER_ID, userId);
request.put(Constants.IDENTIFIER, assessmentIdentifier);
cassandraOperation.deleteRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER_ASSESSMENT_TIME, request);
request.put("starttime", startTime);
SBApiResponse resp = cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER_ASSESSMENT_TIME, request);
request.put(Constants.ASSESSMENT_ID_KEY, assessmentIdentifier);
request.put(Constants.START_TIME, startTime);
request.put(Constants.END_TIME, endTime);
request.put(Constants.ASSESSMENT_READ_RESPONSE, new Gson().toJson(questionSet));
request.put(Constants.STATUS, status);
SBApiResponse resp = cassandraOperation.insertRecord(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_USER_ASSESSMENT_DATA, request);
return resp.get(Constants.RESPONSE).equals(Constants.SUCCESS);
}

@Override
public Date fetchUserAssessmentStartTime(String userId, String assessmentIdentifier) {
@Override
public List<Map<String, Object>> fetchUserAssessmentDataFromDB(String userId, String assessmentIdentifier) {
Map<String, Object> request = new HashMap<>();
request.put(Constants.USER_ID, userId);
request.put(Constants.IDENTIFIER, assessmentIdentifier);
Map<String, Object> existingDataList = cassandraOperation.getRecordsByProperties(Constants.KEYSPACE_SUNBIRD,
Constants.TABLE_USER_ASSESSMENT_TIME, request, null).get(0);
return (Date) existingDataList.get("starttime");
request.put(Constants.ASSESSMENT_ID_KEY, assessmentIdentifier);
List<Map<String, Object>> existingDataList = cassandraOperation.getRecordsByProperties(
Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER_ASSESSMENT_DATA, request, null);
return existingDataList;
}

@Override
public Boolean updateUserAssesmentDataToDB(String userId, String assessmentIdentifier,
Map<String, Object> submitAssessmentRequest, Map<String, Object> submitAssessmentResponse, String status,
Date startTime) {
Map<String, Object> compositeKeys = new HashMap<>();
compositeKeys.put(Constants.USER_ID, userId);
compositeKeys.put(Constants.ASSESSMENT_ID_KEY, assessmentIdentifier);
compositeKeys.put(Constants.START_TIME, startTime);
Map<String, Object> fieldsToBeUpdated = new HashMap<>();
if (!submitAssessmentRequest.isEmpty()) {
fieldsToBeUpdated.put("submitassessmentrequest", new Gson().toJson(submitAssessmentRequest));
}
if (!submitAssessmentResponse.isEmpty()) {
fieldsToBeUpdated.put("submitassessmentresponse", new Gson().toJson(submitAssessmentResponse));
}
if (!status.isEmpty()) {
fieldsToBeUpdated.put(Constants.STATUS, status);
}
cassandraOperation.updateRecord(Constants.KEYSPACE_SUNBIRD, Constants.TABLE_USER_ASSESSMENT_DATA,
fieldsToBeUpdated, compositeKeys);
return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Map<String, Object> submitAssessment(String rootOrg, AssessmentSubmission

// Fetch parent of an assessment with status live
String parentId = contentService.getParentIdentifier(data.getIdentifier());

persist.put("parent", parentId);
persist.put(RESULT, result);
persist.put("sourceId", data.getIdentifier());
Expand Down Expand Up @@ -228,7 +228,7 @@ public Map<String, Object> getAssessmentContent(String courseId, String assessme
&& child.getArtifactUrl().endsWith(".json")) {
// read assessment json file
QuestionSet assessmentContent = mapper.convertValue(outboundRequestHandlerService
.fetchUsingGetWithHeaders(child.getArtifactUrl(), new HashMap<>()),
.fetchUsingGetWithHeaders(child.getArtifactUrl(), new HashMap<>()),
QuestionSet.class);

QuestionSet assessmentQnsSet = assessUtilServ.removeAssessmentAnsKey(assessmentContent);
Expand All @@ -255,4 +255,4 @@ public Map<String, Object> getAssessmentContent(String courseId, String assessme
return result;
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public interface AssessmentServiceV2 {
public SBApiResponse readAssessment(String assessmentIdentifier, String token) throws Exception;

public SBApiResponse readQuestionList(Map<String, Object> requestBody, String authUserToken) throws Exception;

public SBApiResponse retakeAssessment(String assessmentIdentifier, String token) throws Exception;
}
Loading

0 comments on commit 70a4e32

Please sign in to comment.