openvidu-server: REST controller cleaned up

pull/88/merge
pabloFuente 2018-07-04 12:54:27 +02:00
parent ae52864e42
commit a0e50d1022
1 changed files with 16 additions and 15 deletions

View File

@ -37,17 +37,17 @@ import org.springframework.web.bind.annotation.RestController;
import io.openvidu.client.OpenViduException; import io.openvidu.client.OpenViduException;
import io.openvidu.client.internal.ProtocolElements; import io.openvidu.client.internal.ProtocolElements;
import io.openvidu.java.client.MediaMode;
import io.openvidu.java.client.RecordingLayout; import io.openvidu.java.client.RecordingLayout;
import io.openvidu.java.client.RecordingMode; import io.openvidu.java.client.RecordingMode;
import io.openvidu.java.client.RecordingProperties; import io.openvidu.java.client.RecordingProperties;
import io.openvidu.java.client.MediaMode;
import io.openvidu.java.client.SessionProperties; import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.config.OpenviduConfig; import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.ParticipantRole; import io.openvidu.server.core.ParticipantRole;
import io.openvidu.server.core.Session; import io.openvidu.server.core.Session;
import io.openvidu.server.core.SessionManager; import io.openvidu.server.core.SessionManager;
import io.openvidu.server.recording.Recording;
import io.openvidu.server.recording.ComposedRecordingService; import io.openvidu.server.recording.ComposedRecordingService;
import io.openvidu.server.recording.Recording;
/** /**
* *
@ -120,7 +120,7 @@ public class SessionRestController {
String sessionId; String sessionId;
if (customSessionId != null && !customSessionId.isEmpty()) { if (customSessionId != null && !customSessionId.isEmpty()) {
if (sessionManager.sessionidTokenTokenobj.putIfAbsent(customSessionId, new ConcurrentHashMap<>()) != null) { if (sessionManager.sessionidTokenTokenobj.putIfAbsent(customSessionId, new ConcurrentHashMap<>()) != null) {
return new ResponseEntity<JSONObject>(HttpStatus.CONFLICT); return new ResponseEntity<>(HttpStatus.CONFLICT);
} }
sessionId = customSessionId; sessionId = customSessionId;
} else { } else {
@ -137,7 +137,7 @@ public class SessionRestController {
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET) @RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId, public ResponseEntity<JSONObject> getSession(@PathVariable("sessionId") String sessionId,
@RequestParam("webRtcStats") boolean webRtcStats) { @RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
Session session = this.sessionManager.getSession(sessionId); Session session = this.sessionManager.getSession(sessionId);
if (session != null) { if (session != null) {
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON(); JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
@ -149,7 +149,8 @@ public class SessionRestController {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@RequestMapping(value = "/sessions", method = RequestMethod.GET) @RequestMapping(value = "/sessions", method = RequestMethod.GET)
public ResponseEntity<JSONObject> listSessions(@RequestParam("webRtcStats") boolean webRtcStats) { public ResponseEntity<JSONObject> listSessions(
@RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) {
Collection<Session> sessions = this.sessionManager.getSessionObjects(); Collection<Session> sessions = this.sessionManager.getSessionObjects();
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
@ -207,28 +208,28 @@ public class SessionRestController {
if (sessionId == null) { if (sessionId == null) {
// "session" parameter not found // "session" parameter not found
return new ResponseEntity<JSONObject>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
if (!this.openviduConfig.isRecordingModuleEnabled()) { if (!this.openviduConfig.isRecordingModuleEnabled()) {
// OpenVidu Server configuration property "openvidu.recording" is set to false // OpenVidu Server configuration property "openvidu.recording" is set to false
return new ResponseEntity<JSONObject>(HttpStatus.NOT_IMPLEMENTED); return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
} }
Session session = sessionManager.getSession(sessionId); Session session = sessionManager.getSession(sessionId);
if (session == null) { if (session == null) {
// Session does not exist // Session does not exist
return new ResponseEntity<JSONObject>(HttpStatus.NOT_FOUND); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} }
if (session.getParticipants().isEmpty()) { if (session.getParticipants().isEmpty()) {
// Session has no participants // Session has no participants
return new ResponseEntity<JSONObject>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
if (!(session.getSessionProperties().mediaMode().equals(MediaMode.ROUTED)) if (!(session.getSessionProperties().mediaMode().equals(MediaMode.ROUTED))
|| this.recordingService.sessionIsBeingRecorded(session.getSessionId())) { || this.recordingService.sessionIsBeingRecorded(session.getSessionId())) {
// Session is not in ROUTED MediMode or it is already being recorded // Session is not in ROUTED MediMode or it is already being recorded
return new ResponseEntity<JSONObject>(HttpStatus.CONFLICT); return new ResponseEntity<>(HttpStatus.CONFLICT);
} }
RecordingLayout recordingLayout; RecordingLayout recordingLayout;
@ -253,7 +254,7 @@ public class SessionRestController {
if (recordingId == null) { if (recordingId == null) {
// "recordingId" parameter not found // "recordingId" parameter not found
return new ResponseEntity<JSONObject>(HttpStatus.BAD_REQUEST); return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
} }
Recording recording = recordingService.getStartedRecording(recordingId); Recording recording = recordingService.getStartedRecording(recordingId);
@ -261,14 +262,14 @@ public class SessionRestController {
if (recording == null) { if (recording == null) {
if (recordingService.getStartingRecording(recordingId) != null) { if (recordingService.getStartingRecording(recordingId) != null) {
// Recording is still starting // Recording is still starting
return new ResponseEntity<JSONObject>(HttpStatus.NOT_ACCEPTABLE); return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
} }
// Recording does not exist // Recording does not exist
return new ResponseEntity<JSONObject>(HttpStatus.NOT_FOUND); return new ResponseEntity<>(HttpStatus.NOT_FOUND);
} }
if (!this.recordingService.sessionIsBeingRecorded(recording.getSessionId())) { if (!this.recordingService.sessionIsBeingRecorded(recording.getSessionId())) {
// Session is not being recorded // Session is not being recorded
return new ResponseEntity<JSONObject>(HttpStatus.CONFLICT); return new ResponseEntity<>(HttpStatus.CONFLICT);
} }
Session session = sessionManager.getSession(recording.getSessionId()); Session session = sessionManager.getSession(recording.getSessionId());
@ -327,6 +328,6 @@ public class SessionRestController {
responseJson.put("error", status.getReasonPhrase()); responseJson.put("error", status.getReasonPhrase());
responseJson.put("message", errorMessage); responseJson.put("message", errorMessage);
responseJson.put("path", path); responseJson.put("path", path);
return new ResponseEntity<JSONObject>(responseJson, status); return new ResponseEntity<>(responseJson, status);
} }
} }