Skip to content

Commit

Permalink
Merge pull request #86 from jfederico/BBB-142
Browse files Browse the repository at this point in the history
Fix for issue BBB-142
  • Loading branch information
jfederico authored Aug 27, 2018
2 parents 7d32e64 + c04c77b commit 5d31877
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 27 deletions.
26 changes: 11 additions & 15 deletions impl/src/java/org/sakaiproject/bbb/impl/BBBAPIWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,22 +279,19 @@ public Map<String, Object> getRecordings(String meetingID)
throws BBBException {
if (logger.isDebugEnabled()) logger.debug("getRecordings()");

Map<String, Object> recordingsResponse = new HashMap<String, Object>();

if ( api != null ) {
try{
recordingsResponse = api.getRecordings(meetingID);
} catch ( BBBException e) {
recordingsResponse = responseError(e.getMessageKey(), e.getMessage() );
logger.debug("getRecordings.BBBException: message=" + e.getMessage());
} catch ( Exception e) {
recordingsResponse = responseError(BBBException.MESSAGEKEY_GENERALERROR, e.getMessage() );
logger.debug("getRecordings.Exception: message=" + e.getMessage());
}
} else {
if ( api == null ) {
throw new BBBException(BBBException.MESSAGEKEY_INTERNALERROR, "Internal tool configuration error");
}

Map<String, Object> recordingsResponse = new HashMap<String, Object>();
try{
recordingsResponse = api.getRecordings(meetingID);
} catch ( BBBException e) {
recordingsResponse = responseError(e.getMessageKey(), e.getMessage() );
logger.debug("getRecordings.BBBException: message=" + e.getMessage());
} catch ( Exception e) {
recordingsResponse = responseError(BBBException.MESSAGEKEY_GENERALERROR, e.getMessage() );
logger.debug("getRecordings.Exception: message=" + e.getMessage());
}
return recordingsResponse;
}

Expand All @@ -305,7 +302,6 @@ public boolean endMeeting(String meetingID, String password)
if ( api == null ) {
throw new BBBException(BBBException.MESSAGEKEY_INTERNALERROR, "Internal tool configuration error");
}

boolean endMeetingResponse = api.endMeeting(meetingID, password);
return endMeetingResponse;
}
Expand Down
54 changes: 42 additions & 12 deletions impl/src/java/org/sakaiproject/bbb/impl/bbbapi/BaseBBBAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.List;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -314,30 +315,59 @@ public Map<String, Object> getMeetingInfo(String meetingID, String password)
/** Get recordings from BBB server */
public Map<String, Object> getRecordings(String meetingID)
throws BBBException {
try {
// Paginate queries for fetching recordings.
List<String> meetingIDs = Arrays.asList(meetingID.split("\\s*,\\s*"));
int pages = meetingIDs.size() / 25 + 1;
// Fetch recordings in pages.
List<Object> recordings = new ArrayList<Object>();
int fromIndex, toIndex;
for (int page = 1; page <= pages; ++page) {
fromIndex = (page - 1) * 25;
toIndex = page * 25;
if (toIndex > meetingIDs.size()) {
toIndex = meetingIDs.size();
}
List subMeetingIDs = meetingIDs.subList(fromIndex, toIndex);
recordings.addAll(getRecordings(subMeetingIDs));
}
// Prepare and return response with recordings.
Map<String, Object> response = new HashMap<String, Object>();
response.put("returncode", "SUCCESS");
response.put("recordings", recordings);
return response;
} catch (BBBException e) {
logger.debug("getRecordings.Exception: MessageKey=" + e.getMessageKey() + ", Message=" + e.getMessage() );
throw new BBBException(e.getMessageKey(), e.getMessage(), e);
}
}

/** Get recordings from BBB server */
protected List<Object> getRecordings(List meetingIDs)
throws BBBException {
try {
String meetingID = String.join(",", meetingIDs);
StringBuilder query = new StringBuilder();
query.append("meetingID=");
query.append(meetingID);
query.append(getCheckSumParameterForQuery(APICALL_GETRECORDINGS, query.toString()));

Map<String, Object> response = null;
Map<String, Object> response = doAPICall(APICALL_GETRECORDINGS, query.toString());

response = doAPICall(APICALL_GETRECORDINGS, query.toString());

//It makes sure that the date retrived is a unix timestamp
if( response.get("returncode").equals("SUCCESS") && response.get("messageKey") == null ){
for (Object recordingEntry : (List<Object>)response.get("recordings")) {
Map<String,String> items = (Map<String,String>)recordingEntry;
items.put("startTime", getDateAsStringTimestamp(items.get("startTime")) );
items.put("endTime", getDateAsStringTimestamp(items.get("endTime")) );
}
// Make sure that the date retrived is a unix timestamp.
if (response.get("returncode").equals("SUCCESS") && response.get("messageKey") == null) {
for (Object recordingEntry : (List<Object>)response.get("recordings")) {
Map<String, String> items = (Map<String, String>)recordingEntry;
items.put("startTime", getDateAsStringTimestamp(items.get("startTime")) );
items.put("endTime", getDateAsStringTimestamp(items.get("endTime")) );
}
return (List<Object>)response.get("recordings");
}

return response;
} catch (BBBException e) {
logger.debug("getRecordings.Exception: MessageKey=" + e.getMessageKey() + ", Message=" + e.getMessage() );
throw new BBBException(e.getMessageKey(), e.getMessage(), e);
}
return new ArrayList<Object>();
}

/** End/delete a meeting on BBB server */
Expand Down

0 comments on commit 5d31877

Please sign in to comment.