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

Release 6.0.0 s #45

Open
wants to merge 51 commits into
base: release-8.0.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
c152c86
client side evaluation changes
anilkumarkammalapalli Aug 2, 2023
fa88cf6
client side evaluation changes
anilkumarkammalapalli Aug 2, 2023
79991ce
client side evaluation changes
anilkumarkammalapalli Aug 3, 2023
3a00be6
client side evaluation changes
anilkumarkammalapalli Aug 3, 2023
404603e
client side evaluation changes
anilkumarkammalapalli Aug 3, 2023
2feb89e
client side evaluation changes
anilkumarkammalapalli Aug 4, 2023
cf6cd58
client side evaluation changes
anilkumarkammalapalli Aug 4, 2023
12f3bd2
added eval property
anilkumarkammalapalli Aug 11, 2023
75c4d05
added eval property
anilkumarkammalapalli Aug 21, 2023
3dd609c
added eval property
anilkumarkammalapalli Aug 27, 2023
16fa8c7
added property
anilkumarkammalapalli Sep 7, 2023
fd08f18
added property
anilkumarkammalapalli Sep 7, 2023
97e8a67
changed code
anilkumarkammalapalli Sep 7, 2023
3413985
changed code
anilkumarkammalapalli Sep 7, 2023
7fa3058
changed code
anilkumarkammalapalli Sep 11, 2023
9f4a4c6
modify calculate score function
anilkumarkammalapalli Sep 13, 2023
6f15257
updated property
anilkumarkammalapalli Sep 13, 2023
50fc399
updated calculatescore function
anilkumarkammalapalli Sep 13, 2023
d453e62
worked on code review comments
anilkumarkammalapalli Sep 25, 2023
3c81f49
worked on code review comments
anilkumarkammalapalli Sep 25, 2023
b2a41a1
Merge pull request #23 from anilkumarkammalapalli/serverSideEvaluation
anilkumarkammalapalli Sep 25, 2023
0f7e52b
Merge pull request #38 from Sunbird-inQuiry/release-6.2.0
sajeshkayyath Oct 9, 2023
a7420d1
Merge branch 'release-7.0.0' into serverSideEvaluation
anilkumarkammalapalli Nov 2, 2023
c09bea7
updated code
anilkumarkammalapalli Nov 3, 2023
e8f335b
removed unwanted imports
anilkumarkammalapalli Nov 6, 2023
8ce5534
Merge remote-tracking branch 'origin/serverSideEvaluation' into serve…
anilkumarkammalapalli Nov 6, 2023
3de66f8
removed unwanted imports
anilkumarkammalapalli Nov 6, 2023
8a4cb2b
eval change to evalMode
Dec 18, 2023
2468acd
Merge pull request #27 from dilavardavood/release-6.0.0_S
dilavardavood Dec 18, 2023
66e34f1
eval changes to evalMode and object to string
Dec 19, 2023
6b21fba
Merge pull request #28 from dilavardavood/release-6.0.0_S
dilavardavood Dec 19, 2023
a363e2f
eval mode changes
Dec 19, 2023
8450f11
Merge branch 'compass-core-platform:release-6.0.0_S' into release-6.0…
dilavardavood Dec 19, 2023
76a251b
Merge pull request #29 from dilavardavood/release-6.0.0_S
dilavardavood Dec 19, 2023
3db5b31
eval mode changes and graph engine version to 2.12
Dec 19, 2023
d8fe506
pom file graph engine version changes
Dec 19, 2023
efa314b
Merge pull request #30 from dilavardavood/release-6.0.0_S
dilavardavood Dec 19, 2023
7612aaf
pom file scala version changes
Dec 19, 2023
8ac5b75
Merge pull request #31 from dilavardavood/release-6.0.0_S
dilavardavood Dec 19, 2023
fe7995a
PR changes
Dec 20, 2023
89d6a2b
Merge pull request #32 from dilavardavood/serverSideEvaluation
dilavardavood Dec 20, 2023
7a94c1c
assessment actors and controllers removed and added to questionSet
Dec 26, 2023
1525982
Merge pull request #35 from dilavardavood/release-6.0.0_S
darshannagesh Dec 27, 2023
6276648
assessment actor and controller removed
Dec 27, 2023
f9351f3
Merge pull request #36 from dilavardavood/release-6.0.0_S
dilavardavood Dec 27, 2023
d6f9821
moved harcode values to properties
Apr 2, 2024
a03a0eb
removed hardcode api keys
Apr 2, 2024
6c1b81a
Merge remote-tracking branch 'origin/release-6.0.0_S' into release-6.…
Apr 2, 2024
0103617
Merge pull request #43 from dilavardavood/release-6.0.0_S
dilavardavood Apr 2, 2024
1518096
Merge branch 'Sunbird-inQuiry:master' into release-6.0.0_S
anilkumarkammalapalli Apr 8, 2024
7f4c8f1
Merge branch 'release-8.0.0' into release-6.0.0_S
dilavardavood Apr 15, 2024
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 @@ -45,4 +45,35 @@ object AssessmentConstants {
val PRE_CONDITION: String = "preCondition"
val SOURCE: String = "source"
val PRE_CONDITION_VAR : String = "var"
val ASSESSMENTS = "assessments"
val QUESTION_SET_TOKEN = "questionSetToken"
val QUESTION_LIST = "questionList"
val QUESTION_LIST_EDITOR_URL = "question.list.search.editor.url"
val QUESTIONS = "questions"
val CORRECT_RESPONSE = "correctResponse"
val EVENTS = "events"
val EDATA = "edata"
val ITEM = "item"
val ID = "id"
val RESPONSE1 = "response1"
val CARDINALITY = "cardinality"
val MAX_SCORE = "maxScore"
val MULTIPLE = "multiple"
val EDITOR_STATE = "editorState"
val RESPONSE_DECLARATION = "responseDeclaration"
val PASS = "pass"
val YES = "Yes"
val NO = "No"
val RESVALUES = "resvalues"
val PARAMS = "params"
val SCORE = "score"
val VALUE = "value"
val MAPPING = "mapping"
val RESPONSE = "response"
val OUTCOMES = "outcomes"
val OPTIONS = "options"
val EVAL: String = "evalMode"
val SERVER: String = "server"
val FLOWER_BRACKETS: String = "{}"

}
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
package org.sunbird.v5.actors

import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.commons.lang3.StringUtils
import org.sunbird.`object`.importer.{ImportConfig, ImportManager}
import org.sunbird.actor.core.BaseActor
import org.sunbird.common.dto.{Request, Response, ResponseHandler}
import org.sunbird.common.exception.ClientException
import org.sunbird.common.exception.{ClientException, ServerException}
import org.sunbird.common.{DateUtils, Platform}
import org.sunbird.graph.OntologyEngineContext
import org.sunbird.graph.nodes.DataNode
import org.sunbird.graph.schema.DefinitionNode
import org.sunbird.graph.utils.NodeUtil
import org.sunbird.managers.CopyManager
import org.sunbird.utils.{AssessmentErrorCodes, RequestUtil}
import org.sunbird.utils.{AssessmentConstants, AssessmentErrorCodes, RequestUtil}
import org.sunbird.v5.managers.AssessmentV5Manager

import java.util
Expand All @@ -25,7 +27,8 @@ class QuestionActor @Inject()(implicit oec: OntologyEngineContext) extends BaseA

private lazy val importConfig = getImportConfig()
private lazy val importMgr = new ImportManager(importConfig)
val defaultVersion = Platform.config.getNumber("v5_default_qumlVersion")
val defaultVersion:String = Platform.config.getNumber("v5_default_qumlVersion").toString
private val mapper = new ObjectMapper()

override def onReceive(request: Request): Future[Response] = request.getOperation match {
case "createQuestion" => AssessmentV5Manager.create(request)
Expand All @@ -48,6 +51,16 @@ class QuestionActor @Inject()(implicit oec: OntologyEngineContext) extends BaseA
val extPropNameList:util.List[String] = DefinitionNode.getExternalProps(request.getContext.get("graph_id").asInstanceOf[String], request.getContext.get("version").asInstanceOf[String], request.getContext.get("schemaName").asInstanceOf[String]).asJava
request.getRequest.put("fields", extPropNameList)
DataNode.read(request).map(node => {
val serverEvaluable = node.getMetadata.get(AssessmentConstants.EVAL)
val data = serverEvaluable
if (data != null && data == AssessmentConstants.SERVER && !StringUtils.equals(request.getOrDefault("isEditor", "").asInstanceOf[String], "true")) {
val hideEditorResponse = AssessmentV5Manager.hideEditorStateAns(node)
if (StringUtils.isNotEmpty(hideEditorResponse))
node.getMetadata.put(AssessmentConstants.EDITOR_STATE, hideEditorResponse)
val hideCorrectAns = AssessmentV5Manager.hideCorrectResponse(node)
if (StringUtils.isNotEmpty(hideCorrectAns))
node.getMetadata.put(AssessmentConstants.RESPONSE_DECLARATION, hideCorrectAns)
}
if (StringUtils.equalsIgnoreCase(node.getMetadata.get("visibility").asInstanceOf[String], "Private"))
throw new ClientException(AssessmentErrorCodes.ERR_ACCESS_DENIED, s"Question visibility is private, hence access denied")
ResponseHandler.OK.put("question", AssessmentV5Manager.getQuestionMetadata(node, fields, extPropNameList))
Expand Down Expand Up @@ -77,12 +90,46 @@ class QuestionActor @Inject()(implicit oec: OntologyEngineContext) extends BaseA
RequestUtil.validateListRequest(request)
val fields: util.List[String] = JavaConverters.seqAsJavaListConverter(request.get("fields").asInstanceOf[String].split(",").filter(field => StringUtils.isNotBlank(field) && !StringUtils.equalsIgnoreCase(field, "null"))).asJava
request.getRequest.put("fields", fields)
DataNode.search(request).map(nodeList => {
val questionList = nodeList.map(node => AssessmentV5Manager.getQuestionMetadata(node, fields, List().asJava)).asJava
ResponseHandler.OK.put("questions", questionList).put("count", questionList.size)
val extPropNameList: util.List[String] = DefinitionNode.getExternalProps(request.getContext.get("graph_id").asInstanceOf[String], request.getContext.get("version").asInstanceOf[String], request.getContext.get("schemaName").asInstanceOf[String]).asJava
request.getRequest.put("extPropNameList", extPropNameList)

DataNode.search(request).flatMap(nodeList => {
// Use map to process each node and return a Future[util.Map[String, AnyRef]]
val processedNodes: List[Future[util.Map[String, AnyRef]]] = nodeList.map(node => {
val serverEvaluable = node.getMetadata.get(AssessmentConstants.EVAL)
val data = serverEvaluable
if (data != null && data == AssessmentConstants.SERVER && !StringUtils.equals(request.get("isEditor").asInstanceOf[String], "true")) {
val hideEditorStateAns = AssessmentV5Manager.hideEditorStateAns(node)
if (StringUtils.isNotEmpty(hideEditorStateAns))
node.getMetadata.put(AssessmentConstants.EDITOR_STATE, hideEditorStateAns)
val hideCorrectResponse = AssessmentV5Manager.hideCorrectResponse(node)
if (StringUtils.isNotEmpty(hideCorrectResponse))
node.getMetadata.put(AssessmentConstants.RESPONSE_DECLARATION, hideCorrectResponse)
}

// Process each node and return a Future[util.Map[String, AnyRef]]
val result = NodeUtil.serialize(node, fields, node.getObjectType.toLowerCase.replace("Image", ""), request.getContext.get("version").asInstanceOf[String])
val questionMetadata = AssessmentV5Manager.getQuestionMetadata(node, fields, extPropNameList)
val responseMap: util.Map[String, AnyRef] = new util.HashMap[String, AnyRef]()
responseMap.put("question", questionMetadata)
Future.successful(responseMap)
})

// Use Future.sequence to collect the results into a List[util.Map[String, AnyRef]]
val collectedResponses: Future[List[util.Map[String, AnyRef]]] = Future.sequence(processedNodes)

collectedResponses.map { responses =>
val collectedResponsesJava = new java.util.ArrayList[util.Map[String, AnyRef]](responses.asJava)
ResponseHandler.OK.put("questions", collectedResponsesJava).put("count", responses.size)
}.recover {
case _ => // Handle the error case here
val errorMessage = "Failed to retrieve questions."
throw new ServerException("ERR_QUESTION_","" + errorMessage)
}
})
}


def privateRead(request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[Response] = {
val fields: util.List[String] = JavaConverters.seqAsJavaListConverter(request.get("fields").asInstanceOf[String].split(",").filter(field => StringUtils.isNotBlank(field) && !StringUtils.equalsIgnoreCase(field, "null"))).asJava
val extPropNameList:util.List[String] = DefinitionNode.getExternalProps(request.getContext.get("graph_id").asInstanceOf[String], request.getContext.get("version").asInstanceOf[String], request.getContext.get("schemaName").asInstanceOf[String]).asJava
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,24 @@ import org.sunbird.graph.schema.{DefinitionNode, ObjectCategoryDefinition}
import org.sunbird.graph.utils.NodeUtil
import org.sunbird.managers.HierarchyManager.hierarchyPrefix
import org.sunbird.managers.{CopyManager, HierarchyManager, UpdateHierarchyManager}
import org.sunbird.utils.{AssessmentErrorCodes, RequestUtil}
import org.sunbird.utils.{AssessmentConstants, AssessmentErrorCodes, HierarchyConstants, RequestUtil}
import org.sunbird.v5.managers.AssessmentV5Manager

import scala.collection.JavaConverters
import scala.collection.JavaConverters._
import scala.concurrent.{ExecutionContext, Future}
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.scala.DefaultScalaModule
import com.fasterxml.jackson.databind.JsonNode

import scala.collection.mutable

class QuestionSetActor @Inject()(implicit oec: OntologyEngineContext) extends BaseActor {

implicit val ec: ExecutionContext = getContext().dispatcher
private lazy val importConfig = getImportConfig()
private lazy val importMgr = new ImportManager(importConfig)
val defaultVersion = Platform.config.getNumber("v5_default_qumlVersion")
val defaultVersion:String = Platform.config.getNumber("v5_default_qumlVersion").toString

override def onReceive(request: Request): Future[Response] = request.getOperation match {
case "createQuestionSet" => AssessmentV5Manager.create(request)
Expand All @@ -49,6 +54,7 @@ class QuestionSetActor @Inject()(implicit oec: OntologyEngineContext) extends Ba
case "copyQuestionSet" => copy(request)
case "updateCommentQuestionSet" => updateComment(request)
case "readCommentQuestionSet" => AssessmentV5Manager.readComment(request, "comments")
case "assessQuestionSet" => assessment(request)
case _ => ERROR(request.getOperation)
}

Expand All @@ -74,24 +80,55 @@ class QuestionSetActor @Inject()(implicit oec: OntologyEngineContext) extends Ba
}

def getHierarchy(request: Request)(implicit oec: OntologyEngineContext, ec: ExecutionContext): Future[Response] = {
HierarchyManager.getHierarchy(request).map(resp => {
if (StringUtils.equalsIgnoreCase(resp.getResponseCode.toString, "OK")) {
val hierarchyMap = resp.getResult.get("questionSet").asInstanceOf[util.Map[String, AnyRef]]
HierarchyManager.getHierarchy(request).map(resp => {
if (StringUtils.equalsIgnoreCase(resp.getResponseCode.toString, "OK")) {
val hierarchyMap = resp.getResult.get("questionSet").asInstanceOf[util.Map[String, AnyRef]]
val schemaVersion = hierarchyMap.getOrDefault("schemaVersion", "1.1").asInstanceOf[String]
val updateHierarchy = if (StringUtils.equalsIgnoreCase(schemaVersion, "1.0")) {
val hStr: String = JsonUtils.serialize(hierarchyMap)
val regex = """\"identifier\":\"(.*?)\.img\""""
val pattern = regex.r
val updateHStr = pattern.replaceAllIn(hStr, m => s""""identifier":"${m.group(1)}"""")
val updatedHierarchyMap = JsonUtils.deserialize[util.Map[String, AnyRef]](updateHStr, classOf[util.Map[String, AnyRef]])
val schemaVersion = updatedHierarchyMap.getOrDefault("schemaVersion", "1.0").asInstanceOf[String]
val updateHierarchy = if (StringUtils.equalsIgnoreCase("1.0", schemaVersion)) AssessmentV5Manager.getTransformedHierarchy(updatedHierarchyMap) else {
updatedHierarchyMap
AssessmentV5Manager.getTransformedHierarchy(updatedHierarchyMap).asInstanceOf[mutable.Map[String, AnyRef]]
} else {
mutable.Map[String, AnyRef](hierarchyMap.asScala.toSeq: _*)
}
val mode = request.getOrDefault("mode", "").asInstanceOf[String]
val serverEvaluable = request.getOrDefault(HierarchyConstants.SERVEREVALUABLE, HierarchyConstants.FALSE).asInstanceOf[String]
if (!mode.equals("edit") && serverEvaluable.equalsIgnoreCase(HierarchyConstants.TRUE)) {
val childrenList = updateHierarchy.get(HierarchyConstants.CHILDREN).getOrElse(new util.ArrayList[java.util.Map[String, AnyRef]]())
.asInstanceOf[util.ArrayList[java.util.Map[String, AnyRef]]]
val updatedChildrenList = childrenList.asScala.map(child => {
val maxQuestions = Option(child.get(HierarchyConstants.MAXQUESTIONS)).map(_.asInstanceOf[Int]).getOrElse(0)
val shuffle = Option(child.get(HierarchyConstants.SHUFFLE)).map(_.asInstanceOf[Boolean]).getOrElse(false)
val randomizedChild = if (shuffle) HierarchyManager.shuffleQuestions(child) else child
val limitedChild = HierarchyManager.limitQuestions(randomizedChild, maxQuestions)

limitedChild
}).asJava
val serverEvaluable = updatedChildrenList.get(0).get(HierarchyConstants.EVAL)
if (serverEvaluable != null && serverEvaluable == HierarchyConstants.SERVER) {
request.put(HierarchyConstants.EVAL_MODE, HierarchyConstants.SERVER)
} else {
request.put(HierarchyConstants.EVAL_MODE, HierarchyConstants.CLIENT)
}
resp.getResult.remove("questionSet")
resp.put("questionset", updateHierarchy)
resp
} else resp
})
}
val nestedChildrenIdentifiers = HierarchyManager.getNestedChildrenIdentifiers(updatedChildrenList)
val mergedMap: util.Map[String, String] = HierarchyManager.createMergedMap(request, nestedChildrenIdentifiers)
val userMapJson = JsonUtils.serialize(mergedMap)
val jwtToken = HierarchyManager.generateJwtToken(userMapJson)
updateHierarchy.put(HierarchyConstants.QUESTIONSETTOKEN, jwtToken)
updateHierarchy.put(HierarchyConstants.IDENTIFIER, request.get("contentID"))
updateHierarchy.put(HierarchyConstants.CHILDREN, updatedChildrenList)
resp.getResult.put("questionset", updateHierarchy.asJava)
}
resp
} else {
resp.getResult.remove("questionSet")
resp
}
})
}

@throws[Exception]
def review(request: Request): Future[Response] = {
Expand Down Expand Up @@ -262,5 +299,12 @@ class QuestionSetActor @Inject()(implicit oec: OntologyEngineContext) extends Ba
}
}
}
private def assessment(req: Request): Future[Response] = {
val assessments = req.getRequest.getOrDefault(AssessmentConstants.ASSESSMENTS, new util.ArrayList[util.Map[String, AnyRef]]).asInstanceOf[util.List[util.Map[String, AnyRef]]]
val quesDoIds = AssessmentV5Manager.validateAssessRequest(req)
val list: Response = AssessmentV5Manager.questionList(quesDoIds)
AssessmentV5Manager.calculateScore(list, assessments)
Future(ResponseHandler.OK.put(AssessmentConstants.QUESTIONS, req.getRequest))
}
}

Loading