Skip to content

Commit 50b7e1f

Browse files
committed
fix an issue where embed activitites are not processed on doCreate
scroll to bottom of repl after result is displayed
1 parent b617223 commit 50b7e1f

2 files changed

Lines changed: 38 additions & 6 deletions

File tree

src/main/java/edu/cmu/oli/content/boundary/managers/ContentResourceManager.java

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,42 @@ public Resource doCreate(String packageIdOrGuid, String resourceTypeId, JsonElem
544544
pathFrom = "organizations/" + random + "/" + "organization.xml";
545545
}
546546

547+
String pathTo = jsonCapable ? pathFrom.substring(0, pathFrom.lastIndexOf(".xml")) + ".json" : pathFrom;
548+
549+
FileNode fileNode = new FileNode(contentPackage.getVolumeLocation(), pathFrom, pathTo,
550+
jsonCapable ? "application/json" : "text/xml");
551+
resource.setFileNode(fileNode);
552+
resource.setContentPackage(contentPackage);
553+
554+
// check if the object is an embed_activity to extract asset content
555+
if (resourceContent.getAsJsonObject().has("embed_activity")) {
556+
JsonObject embedActivity = resourceContent.getAsJsonObject().get("embed_activity").getAsJsonObject();
557+
JsonArray embedActivityChildren = embedActivity.get("#array").getAsJsonArray();
558+
559+
// if embed_activity is a REPL, make sure required assets are in place
560+
boolean isReplActivity = AppUtils.inferEmbedActivityType(embedActivity) == EmbedActivityType.REPL;
561+
if (isReplActivity) {
562+
this.processReplEmbedActivity(resource, embedActivity);
563+
}
564+
565+
for (JsonElement child : embedActivityChildren) {
566+
if (child.getAsJsonObject().has("assets")) {
567+
JsonArray assets = child.getAsJsonObject().get("assets").getAsJsonObject().get("#array").getAsJsonArray();
568+
569+
for (JsonElement asset : assets) {
570+
if (asset.getAsJsonObject().get("asset").getAsJsonObject().has("content")) {
571+
// extract asset content
572+
try {
573+
this.processAssetContent(resource, asset.getAsJsonObject().get("asset").getAsJsonObject());
574+
} catch (Throwable t) {
575+
log.error(t.toString());
576+
}
577+
}
578+
}
579+
}
580+
}
581+
}
582+
547583
TypedQuery<Resource> query = em.createQuery(
548584
"select r from Resource r where r.contentPackage.guid = :pkgGuid and r.id = :id", Resource.class);
549585
query.setParameter("id", resource.getId());
@@ -558,12 +594,6 @@ public Resource doCreate(String packageIdOrGuid, String resourceTypeId, JsonElem
558594
// Parse update payload into final xml and json documents
559595
Map<String, String> contentValues = contentValues(resourceContent, resource, jsonCapable);
560596

561-
String pathTo = jsonCapable ? pathFrom.substring(0, pathFrom.lastIndexOf(".xml")) + ".json" : pathFrom;
562-
563-
FileNode fileNode = new FileNode(contentPackage.getVolumeLocation(), pathFrom, pathTo,
564-
jsonCapable ? "application/json" : "text/xml");
565-
resource.setFileNode(fileNode);
566-
resource.setContentPackage(contentPackage);
567597
validateXmlContent(contentPackage.getGuid(), resource, contentValues.get("xmlContent"), throwErrors);
568598

569599
RevisionBlob revisionBlob = jsonCapable

src/main/resources/repl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ define(function () {
495495
ActivityEmbed.repl.writeln('---------------------------------------');
496496
ActivityEmbed.repl.writeln('RESULT:');
497497
ActivityEmbed.repl.write(response.result);
498+
ActivityEmbed.repl.terminal.scrollToBottom();
498499

499500
// check if there was a question and part to process. If not, then this is treated as
500501
// an ungraded activity, so simply return
@@ -578,6 +579,7 @@ define(function () {
578579
ActivityEmbed.repl.writeln('---------------------------------------');
579580
ActivityEmbed.repl.writeln('RESULT:');
580581
ActivityEmbed.repl.write(response.result);
582+
ActivityEmbed.repl.terminal.scrollToBottom();
581583

582584
// check if there was a question and part to process. If not, then this is treated as
583585
// an ungraded activity, so simply return

0 commit comments

Comments
 (0)