Skip to content
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 @@ -27,6 +27,7 @@ class ScormMimeTypeMgrImpl(implicit ss: StorageService) extends BaseMimeTypeMana
val manifestXml = getSecureXml(manifestFile)
val scormVersion = detectScormVersion(manifestXml)
val scoList = getScoList(manifestXml, scormVersion)
val maxAttempts = detectMaxAttempts(manifestXml, scormVersion)

if (scoList.isEmpty)
throw new ClientException("ERR_INVALID_FILE", "No SCOs found in imsmanifest.xml!")
Expand All @@ -48,18 +49,18 @@ class ScormMimeTypeMgrImpl(implicit ss: StorageService) extends BaseMimeTypeMana

extractPackageInCloud(objectId, uploadFile, node, "snapshot", false)

Future(
Map[String, AnyRef](
"identifier" -> objectId,
"artifactUrl" -> urls(IDX_S3_URL),
"s3Key" -> urls(IDX_S3_KEY),
"size" -> getFileSize(uploadFile).asInstanceOf[AnyRef],
"launchFile" -> launchFile,
"scoList" -> javaScoList,
"scormVersion" -> scormVersion
)
val baseResult = Map[String, AnyRef](
"identifier" -> objectId,
"artifactUrl" -> urls(IDX_S3_URL),
"s3Key" -> urls(IDX_S3_KEY),
"size" -> getFileSize(uploadFile).asInstanceOf[AnyRef],
"launchFile" -> launchFile,
"scoList" -> javaScoList,
"scormVersion" -> scormVersion
)

Future(maxAttempts.fold(baseResult)(limit => baseResult + ("maxAttempts" -> limit.asInstanceOf[AnyRef])))

} else {
TelemetryManager.error("ERR_INVALID_FILE:: Invalid SCORM package: imsmanifest.xml not found for objectId: " + objectId)
throw new ClientException("ERR_INVALID_FILE", "Invalid SCORM package: imsmanifest.xml is missing!")
Expand Down Expand Up @@ -90,6 +91,12 @@ class ScormMimeTypeMgrImpl(implicit ss: StorageService) extends BaseMimeTypeMana
}
}

private def detectMaxAttempts(xml: Elem, scormVersion: String): Option[Int] = {
if (scormVersion != "2004") None
else (xml \\ "limitConditions").flatMap(_.attribute("attemptLimit").map(_.text.trim)).headOption
.flatMap(v => scala.util.Try(v.toInt).toOption)
}

private def getValidatedLaunchFile(extractionBasePath: String, launchFile: String): String = {
if (launchFile.isEmpty) {
throw new ClientException("ERR_INVALID_FILE", "Invalid launch file path!")
Expand Down
3 changes: 3 additions & 0 deletions scripts/definition-scripts/SCORM_Content.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ curl -L -X POST '{{host}}/object/category/definition/v4/create' \
"parameters": { "type": "string" }
}
}
},
"maxAttempts": {
"type": "number"
}
}
}
Expand Down
Loading