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

Revert MCQ question commit (#76) #78

Merged
Merged
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 @@ -71,62 +71,6 @@ object UpdateHierarchyManager {
.getOrDefault(HierarchyConstants.OBJECT_TYPE, "").asInstanceOf[String], "Question"))
throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Question cannot have children in hierarchy")
})
val iterator = nodesModified.entrySet().iterator()
while (iterator.hasNext) {
val entry = iterator.next()
val questionData = entry.getValue() match {
case map: java.util.HashMap[_, _] => map.asInstanceOf[java.util.HashMap[String, AnyRef]]
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Invalid question data.")
}
val metadata = Option(questionData.get(HierarchyConstants.METADATA)) match {
case Some(map: java.util.HashMap[_, _]) => map.asInstanceOf[java.util.HashMap[String, AnyRef]]
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing metadata.")
}
if (metadata.get(HierarchyConstants.PRIMARY_CATEGORY) == HierarchyConstants.MCQ) {
val primaryCategory = Option(metadata.get(HierarchyConstants.PRIMARY_CATEGORY)) match {
case Some(category: String) => category
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing primary category.")
}

if (primaryCategory == HierarchyConstants.MCQ) {
val choices = Option(metadata.get(HierarchyConstants.CHOICES)) match {
case Some(choiceMap: java.util.HashMap[_, _]) =>
val options = Option(choiceMap.get(HierarchyConstants.OPTIONS)) match {
case Some(optionsList: java.util.List[_]) =>
optionsList.asInstanceOf[java.util.List[java.util.HashMap[String, AnyRef]]].asScala.toList
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing options.")
}
options
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing choices.")
}

for (option <- choices) {
val answerType = Option(option.get(HierarchyConstants.ANSWER)) match {
case Some(answer) => answer
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing answer type.")
}

if (!answerType.isInstanceOf[java.lang.Boolean]) {
val questionBody = Option(metadata.get(HierarchyConstants.BODY)) match {
case Some(body: String) => body
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing question body.")
}

val optionBody = Option(option.get(HierarchyConstants.VALUE)) match {
case Some(valueMap: java.util.HashMap[_, _]) =>
Option(valueMap.get(HierarchyConstants.BODY)) match {
case Some(body) => body
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing option body.")
}
case _ => throw new ClientException("ERR_QS_UPDATE_HIERARCHY", "Error: Missing option value map.")
}

throw new ClientException("ERR_QS_UPDATE_HIERARCHY", s"Error: Question : '$questionBody', Option : '$optionBody' has a non-boolean answer. The answer value should be either true or false.")
}
}
}
}
}
(nodesModified, hierarchy)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,4 @@ object HierarchyConstants {
val SOURCE: String = "source"
val PRE_CONDITION: String = "preCondition"
val QUESTION_VISIBILITY: List[String] = List("Default", "Parent")
val OPTIONS = "options"
val CHOICES = "choices"
val ANSWER = "answer"
val BODY = "body"
val VALUE = "value"
val PRIMARY_CATEGORY = "primaryCategory"
val MCQ = "Multiple Choice Question"


}
Loading