From f8180d3cee643c24fdc4b205aeee11d9c5afdac5 Mon Sep 17 00:00:00 2001 From: Felipe Cecagno Date: Fri, 22 Feb 2013 17:44:24 -0300 Subject: [PATCH] very first implementation of the getRecordings call filtering by metadata; the idea is the same as on create, the user will specify some parameters as meta_*, and the call will return just the recordings that match all the metadata specified; it continues working with the meetingID filter, and both can be used together --- .../web/controllers/ApiController.groovy | 1 + .../org/bigbluebutton/api/MeetingService.java | 4 +++ .../api/ParamsProcessorUtil.java | 27 +++++++++++-------- .../bigbluebutton/api/RecordingService.java | 24 +++++++++++++++++ 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy b/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy index f84d646ac1..235b6446ef 100755 --- a/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy +++ b/bigbluebutton-web/grails-app/controllers/org/bigbluebutton/web/controllers/ApiController.groovy @@ -828,6 +828,7 @@ class ApiController { // Everything is good so far. Translate the external meeting ids to an internal meeting ids. ArrayList internalMeetingIds = paramsProcessorUtil.convertToInternalMeetingId(externalMeetingIds); HashMap recs = meetingService.getRecordings(internalMeetingIds); + recs = meetingService.filterRecordingsByMetadata(recs, paramsProcessorUtil.getMetadataFromParams(params)); if (recs.isEmpty()) { response.addHeader("Cache-Control", "no-cache") diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/api/MeetingService.java b/bigbluebutton-web/src/java/org/bigbluebutton/api/MeetingService.java index dab959f3c6..0e019072f7 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/api/MeetingService.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/api/MeetingService.java @@ -113,6 +113,10 @@ public class MeetingService { return recs; } + public Map filterRecordingsByMetadata(Map recordings, Map metadataFilters) { + return recordingService.filterRecordingsByMetadata(recordings, metadataFilters); + } + public HashMap reorderRecordings(ArrayList olds){ HashMap map= new HashMap(); for(Recording r:olds){ diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/api/ParamsProcessorUtil.java b/bigbluebutton-web/src/java/org/bigbluebutton/api/ParamsProcessorUtil.java index 0f0065ede2..d6a7d2b467 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/api/ParamsProcessorUtil.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/api/ParamsProcessorUtil.java @@ -265,16 +265,7 @@ public class ParamsProcessorUtil { } // Collect metadata for this meeting that the third-party app wants to store if meeting is recorded. - Map meetingInfo = new HashMap(); - for (String key: params.keySet()) { - if (key.contains("meta")&&key.indexOf("meta")==0){ - String[] meta = key.split("_"); - if(meta.length == 2){ - log.debug("Got metadata {} = {}", key, params.get(key)); - meetingInfo.put(meta[1].toLowerCase(), params.get(key)); - } - } - } + Map meetingInfo = getMetadataFromParams(params); // Create a unique internal id by appending the current time. This way, the 3rd-party // app can reuse the external meeting id. @@ -290,7 +281,21 @@ public class ParamsProcessorUtil { return meeting; } - + + public Map getMetadataFromParams(Map params) { + // Collect metadata for this meeting that the third-party app wants to store if meeting is recorded. + Map meetingInfo = new HashMap(); + for (String key: params.keySet()) { + if (key.contains("meta")&&key.indexOf("meta")==0){ + String[] meta = key.split("_"); + if(meta.length == 2){ + log.debug("Got metadata {} = {}", key, params.get(key)); + meetingInfo.put(meta[1].toLowerCase(), params.get(key)); + } + } + } + return meetingInfo; + } public String getApiVersion() { return apiVersion; diff --git a/bigbluebutton-web/src/java/org/bigbluebutton/api/RecordingService.java b/bigbluebutton-web/src/java/org/bigbluebutton/api/RecordingService.java index d56580fb9d..aa463fb13e 100755 --- a/bigbluebutton-web/src/java/org/bigbluebutton/api/RecordingService.java +++ b/bigbluebutton-web/src/java/org/bigbluebutton/api/RecordingService.java @@ -4,6 +4,8 @@ import java.io.File; import java.io.FileFilter; import java.io.IOException; import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; import org.bigbluebutton.api.domain.Recording; import org.slf4j.Logger; @@ -57,6 +59,28 @@ public class RecordingService { return recs; } + public boolean recordingMatchesMetadata(Recording recording, Map metadataFilters) { + for (Map.Entry filter : metadataFilters.entrySet()) { + String metadataValue = recording.getMetadata().get(filter.getKey()); + if (metadataValue != null && metadataValue.equals(filter.getValue())) { + // the recording has the metadata specified + // AND the value is the same as the filter + } else { + return false; + } + } + return true; + } + + public Map filterRecordingsByMetadata(Map recordings, Map metadataFilters) { + Map resultRecordings = new HashMap(); + for (Map.Entry entry : recordings.entrySet()) { + if (recordingMatchesMetadata(entry.getValue(), metadataFilters)) + resultRecordings.put(entry.getKey(), entry.getValue()); + } + return resultRecordings; + } + public boolean existAnyRecording(ArrayList idList){ ArrayList publishList=getAllRecordingIds(publishedDir); ArrayList unpublishList=getAllRecordingIds(unpublishedDir);