@@ -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
0 commit comments