From 418244774a244125b60e0830ae91764b3e9a9e9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Florian=20Gn=C3=A4gi?= <gnaegi@frentix.com>
Date: Wed, 19 Aug 2020 17:10:34 +0200
Subject: [PATCH] OO-4860 use meetingID and not identifier when query OpenCast
 for BBB recordings

---
 .../bigbluebutton/BigBlueButtonMeeting.java   | 139 +++++++++++++++++-
 .../manager/BigBlueButtonMeetingDAO.java      |   3 +
 ...igBlueButtonOpenCastRecordingsHandler.java |  17 ++-
 3 files changed, 149 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/olat/modules/bigbluebutton/BigBlueButtonMeeting.java b/src/main/java/org/olat/modules/bigbluebutton/BigBlueButtonMeeting.java
index d205eb7264c..f7e4662fbaf 100644
--- a/src/main/java/org/olat/modules/bigbluebutton/BigBlueButtonMeeting.java
+++ b/src/main/java/org/olat/modules/bigbluebutton/BigBlueButtonMeeting.java
@@ -37,81 +37,208 @@ public interface BigBlueButtonMeeting extends ModifiedInfo, CreateInfo {
 	
 	public Long getKey();
 	
+	/**
+	 * The meeting ID used when creating a BBB Meeting via API. In the BBB recording
+	 * metadata this is referred as "externalId".
+	 * 
+	 * @return
+	 */
 	public String getMeetingId();
 	
 	public String getAttendeePassword();
 
 	public String getModeratorPassword();
 	
+	/**
+	 * The name of the meeting used in OpenOlat and BBB
+	 * 
+	 * @return
+	 */
 	public String getName();
 	
 	public void setName(String name);
 	
+	/**
+	 * The description of the meeting is displayed in OpenOlat before joining
+	 * 
+	 * @return
+	 */
 	public String getDescription();
 	
 	public void setDescription(String description);
 	
+	/**
+	 * The welcome message is displayed in BBB after joining the meeting. 
+	 * 
+	 * @return
+	 */
 	public String getWelcome();
 	
 	public void setWelcome(String welcome);
 	
+	/**
+	 * The layout pre sets arrangements of cams and presentations
+	 * @return
+	 */
 	public BigBlueButtonMeetingLayoutEnum getMeetingLayout();
 	
 	public void setMeetingLayout(BigBlueButtonMeetingLayoutEnum layout);
 	
+	/**
+	 * Permanent meetings have no start and end date. E.g. for groups who want to
+	 * make spontaneous meetings without scheduling meetings in the first place.
+	 * Note that permanent can quickly consume the available meeting quota as the
+	 * count as current active meetings.
+	 * 
+	 * @return
+	 */
 	public boolean isPermanent();
 	
 	public void setPermanent(boolean permanent);
 	
+	/**
+	 * Allow joining of external users via URL and name input field. 
+	 * @return
+	 */
 	public boolean isGuest();
 	
 	public void setGuest(boolean guest);
-	
+
+	/**
+	 * The identifier is used in the OpenOlat BBB dispatcher to not expose the real
+	 * meeting ID to the user, e.g. when accessed by external guests. BBB does not now
+	 * this ID, it is OO internal only. 
+	 * 
+	 * @return
+	 */
 	public String getIdentifier();
 
+	/**
+	 * The readable identifier is similar to the identifier but can be modified by
+	 * users in the edit for to create a human readable URL when sending the meeting
+	 * join url via email to participants. BBB does not now this ID, it is OO
+	 * internal only.
+	 * 
+	 * @return
+	 */
 	public String getReadableIdentifier();
 
 	public void setReadableIdentifier(String readableIdentifier);
 	
+	
+	/**
+	 * If not a permanent meeting, the meetings starts at this date. Participants
+	 * and guests can join at this time.
+	 * 
+	 * @return
+	 */
 	public Date getStartDate();
 	
 	public void setStartDate(Date start);
-	
+
+	/**
+	 * The minutes a meeting can be joined by the coaches prior to the start time,
+	 * e.g. for preparation of slides. Is not taken into account room quota
+	 * calculation.
+	 * 
+	 * @return
+	 */
 	public long getLeadTime();
 	
 	public void setLeadTime(long leadTime);
 
+	/**
+	 * The calculated date when the BBB meeting can be opened technically
+	 * @return
+	 */
 	public Date getStartWithLeadTime();
-	
+
+
+	/**
+	 * If not a permanent meeting, the meetings ends at this date. 
+	 * 
+	 * @return
+	 */
 	public Date getEndDate();
 	
 	public void setEndDate(Date end);
 
+	/**
+	 * The minutes a meeting can be over time. Is not taken into account room quota
+	 * calculation.
+	 * 
+	 * @return
+	 */
 	public long getFollowupTime();
 	
 	public void setFollowupTime(long followupTime);
 
+	/**
+	 * The calculated latest date when the BBB meeting is closed automatically
+	 * 
+	 * @return
+	 */
 	public Date getEndWithFollowupTime();
 	
+	/**
+	 * Flag to auto or manual publish the recordings
+	 * 
+	 * @return
+	 */
 	public BigBlueButtonRecordingsPublishingEnum getRecordingsPublishingEnum();
 
 	public void setRecordingsPublishingEnum(BigBlueButtonRecordingsPublishingEnum publishing);
 	
+	/**
+	 * The plain text name of the presenter or main organizer. By default the name
+	 * of the creator but can be change to anything. Metadata just for display
+	 * purposes.
+	 * 
+	 * @return
+	 */
 	public String getMainPresenter();
-	
+
 	public void setMainPresenter(String name);
-	
+
+	/**
+	 * The identity who create the meeting
+	 * 
+	 * @return
+	 */
 	public Identity getCreator();
 	
 	public BigBlueButtonMeetingTemplate getTemplate();
 
 	public void setTemplate(BigBlueButtonMeetingTemplate template);
 	
+	/**
+	 * The group if it is a group meeting. Can be null for non-group meetings. 
+	 * @return
+	 */
 	public BusinessGroup getBusinessGroup();
 
+	/**
+	 * The course repository entry in which the meetings was created. Can be null,
+	 * e.g. when it is a group meeting.
+	 * 
+	 * @return
+	 */
 	public RepositoryEntry getEntry();
 
+	/**
+	 * The sub identifier for the repository entry, normally the course node ID. Can
+	 * be null.
+	 * 
+	 * @return
+	 */
 	public String getSubIdent();
-	
+
+	/**
+	 * The server on which the meeting runs. Can be null if the meeting has not yet
+	 * been created on the BBB server. Permanent meetings will always run on the
+	 * same BBB server.
+	 * 
+	 * @return
+	 */
 	public BigBlueButtonServer getServer();
 }
diff --git a/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonMeetingDAO.java b/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonMeetingDAO.java
index 7b4c400f25d..f0f1243a49d 100644
--- a/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonMeetingDAO.java
+++ b/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonMeetingDAO.java
@@ -61,15 +61,18 @@ public class BigBlueButtonMeetingDAO {
 		meeting.setCreationDate(new Date());
 		meeting.setLastModified(meeting.getCreationDate());
 		meeting.setName(name);
+		// ID for BBB used as meetingID, in metadata as "externalId"
 		meeting.setMeetingId(UUID.randomUUID().toString());
 		meeting.setAttendeePassword(UUID.randomUUID().toString());
 		meeting.setModeratorPassword(UUID.randomUUID().toString());
 		meeting.setMeetingLayout(BigBlueButtonMeetingLayoutEnum.standard);
 		
 		meeting.setGuest(false);
+		// ID for OO internal dispatcher (guest access). BBB does not now this ID. 
 		meeting.setIdentifier(UUID.randomUUID().toString());
 		
 		meeting.setEntry(entry);
+		// ID for OO internal context subinformation such as the course node ID
 		meeting.setSubIdent(subIdent);
 		meeting.setBusinessGroup(businessGroup);
 		
diff --git a/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonOpenCastRecordingsHandler.java b/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonOpenCastRecordingsHandler.java
index b88fe774c72..82ead0e12f6 100644
--- a/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonOpenCastRecordingsHandler.java
+++ b/src/main/java/org/olat/modules/bigbluebutton/manager/BigBlueButtonOpenCastRecordingsHandler.java
@@ -105,12 +105,12 @@ public class BigBlueButtonOpenCastRecordingsHandler implements BigBlueButtonReco
 			return Collections.emptyList();
 		}
 		
-		List<OpencastEvent> events = opencastService.getEvents(meeting.getIdentifier());
+		List<OpencastEvent> events = opencastService.getEvents(meeting.getMeetingId());
 		List<BigBlueButtonRecording> recordings = new ArrayList<>(events.size());
 		for (OpencastEvent event : events) {
 			String recordId = event.getIdentifier();
 			String name = event.getTitle();
-			String meetingId = meeting.getIdentifier();
+			String meetingId = meeting.getMeetingId();
 			Date startTime = event.getStart();
 			Date endTime = event.getEnd();
 			String url = null;
@@ -213,7 +213,16 @@ public class BigBlueButtonOpenCastRecordingsHandler implements BigBlueButtonReco
 			errors.append(new BigBlueButtonError(BigBlueButtonErrorCodes.opencastDisabled));
 			return false;
 		}
-		
-		return opencastService.deleteEvents(meeting.getIdentifier());
+		boolean success = false;
+		for (BigBlueButtonRecording recording : recordings) {
+			boolean ok = opencastService.deleteEvents(recording.getRecordId());			
+			if (!ok) {
+				log.warn("Could not delete open case event::{} for meetingId::{})", recording.getRecordId(),  meeting.getMeetingId());
+				errors.append(new BigBlueButtonError(BigBlueButtonErrorCodes.unkown));
+				return false;
+			}
+			success &= ok;			
+		}
+		return success;
 	}
 }
-- 
GitLab