From 0506db4f262acfa1f12523c6948f47c37e8ac726 Mon Sep 17 00:00:00 2001 From: jfederico Date: Sat, 24 Sep 2016 10:54:09 -0400 Subject: [PATCH] bbb-web: Fixed issue with publish/unpublish removing extensions from metadata.xml --- .../api/RecordingServiceHelperImp.groovy | 65 +++++++++++++++++-- 1 file changed, 59 insertions(+), 6 deletions(-) diff --git a/bigbluebutton-web/src/groovy/org/bigbluebutton/api/RecordingServiceHelperImp.groovy b/bigbluebutton-web/src/groovy/org/bigbluebutton/api/RecordingServiceHelperImp.groovy index 8e1bcca7f9..a6f1fe96fb 100755 --- a/bigbluebutton-web/src/groovy/org/bigbluebutton/api/RecordingServiceHelperImp.groovy +++ b/bigbluebutton-web/src/groovy/org/bigbluebutton/api/RecordingServiceHelperImp.groovy @@ -19,9 +19,11 @@ package org.bigbluebutton.api; +import groovy.json.JsonBuilder; import groovy.util.XmlSlurper; import groovy.util.slurpersupport.Attributes; import groovy.util.slurpersupport.GPathResult; +import groovy.xml.MarkupBuilder; import java.io.File; import java.io.FileNotFoundException; @@ -71,7 +73,7 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { public void writeRecordingInfo(String path, Recording info) { def writer = new StringWriter() def builder = new groovy.xml.MarkupBuilder(writer) - def metadataXml = builder.recording { + builder.recording { builder.id(info.getId()) builder.state(info.getState()) builder.published(info.isPublished()) @@ -84,7 +86,17 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { builder.format(info.getPlaybackFormat()) builder.link(info.getPlaybackLink()) builder.duration(info.getPlaybackDuration()) - builder.extension(info.getPlaybackExtensions()) + def extensions = info.getPlaybackExtensions() + if ( !extensions.isEmpty() ) { + builder.extensions { + extensions.each { extension -> + def extensionType = extension.getType() + builder."${extensionType}"{ + extensionPropertiesToXML(builder, extension.getProperties()) + } + } + } + } } } Map metainfo = info.getMetadata(); @@ -104,7 +116,7 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { File file = new File(dir.getPath() + File.separatorChar + "metadata.xml"); if ( file ) { def recording = new XmlSlurper().parse(file); - return getInfo(recording); + return getInfo(recording); } } catch ( FileNotFoundException e) { // Do nothing, just return null @@ -117,6 +129,7 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { private Recording getInfo(GPathResult rec) { Recording r = new Recording(); + //Add basic information r.setId(rec.id.text()); r.setState(rec.state.text()); r.setPublished(Boolean.parseBoolean(rec.published.text())); @@ -128,11 +141,14 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { r.setPlaybackDuration(rec.playback.duration.text()); } + //Add extensions List extensions = new ArrayList() rec.playback.extensions.children().each { extension -> - extensions.add( new Extension(extension.name(),parse(extension)) ) + extensions.add( new Extension(extension.name(), extensionPropertiesToMap(extension)) ) } r.setPlaybackExtensions(extensions) + + //Add metadata Map meta = new HashMap(); rec.meta.children().each { anode -> meta.put(anode.name().toString(), anode.text().toString()); @@ -170,7 +186,7 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { } } //Add content to the node - if ( map[node.name()] == null) { + if ( map[node.name()] == null ) { map[node.name()] = nodeContent } else { if ( ! (map[node.name()] instanceof List) ) { @@ -181,7 +197,7 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { map } - private Map parse(GPathResult xml) { + private Map extensionPropertiesToMap(GPathResult xml) { Map map = [ : ] xml.children().each { if ( it.children().size() == 0 ) { @@ -193,4 +209,41 @@ public class RecordingServiceHelperImp implements RecordingServiceHelper { map } + private void processMap(builder, node) { + node.each { key, value -> + if ( value instanceof Collection ) { + processCollection(builder, key, value) + } else if ( value instanceof Map ) { + if ( value.containsKey("text") && value.containsKey("attributes") ) { + builder."${key}"(value["attributes"], value["text"]) + } else { + builder."${key}" { + processMap(builder, value) + } + } + } else { + builder."${key}"(value) + } + } + } + + private void processCollection(builder, nodesKey, nodes) { + nodes.each { node -> + processMap(builder, [ "${nodesKey}" : node ]) + } + } + + private void extensionPropertiesToXML(builder, properties) { + properties.each { propertyKey, propertyValue -> + if ( propertyValue instanceof Collection ) { + builder."${propertyKey}" { + processCollection(builder, propertyKey, propertyValue) + } + } else { + builder."${propertyKey}" { + processMap(builder, propertyValue) + } + } + } + } }