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.internal.ProtocolElements;
import io.openvidu.java.client.MediaMode;
import io.openvidu.java.client.RecordingLayout;
import io.openvidu.java.client.RecordingMode;
import io.openvidu.java.client.RecordingProperties;
import io.openvidu.java.client.MediaMode;
import io.openvidu.java.client.SessionProperties;
import io.openvidu.server.config.OpenviduConfig;
import io.openvidu.server.core.ParticipantRole;
import io.openvidu.server.core.Session;
import io.openvidu.server.core.SessionManager;
import io.openvidu.server.recording.Recording;
import io.openvidu.server.recording.ComposedRecordingService;
import io.openvidu.server.recording.Recording;
/**
*
@ -120,7 +120,7 @@ public class SessionRestController {
String sessionId;
if (customSessionId != null && !customSessionId.isEmpty()) {
if (sessionManager.sessionidTokenTokenobj.putIfAbsent(customSessionId, new ConcurrentHashMap<>()) != null) {
return new ResponseEntity<JSONObject>(HttpStatus.CONFLICT);
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
sessionId = customSessionId;
} else {
@ -137,7 +137,7 @@ public class SessionRestController {
@RequestMapping(value = "/sessions/{sessionId}", method = RequestMethod.GET)
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);
if (session != null) {
JSONObject response = (webRtcStats == true) ? session.withStatsToJSON() : session.toJSON();
@ -149,7 +149,8 @@ public class SessionRestController {
@SuppressWarnings("unchecked")
@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();
JSONObject json = new JSONObject();
JSONArray jsonArray = new JSONArray();
@ -207,28 +208,28 @@ public class SessionRestController {
if (sessionId == null) {
// "session" parameter not found
return new ResponseEntity<JSONObject>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
if (!this.openviduConfig.isRecordingModuleEnabled()) {
// 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);
if (session == null) {
// Session does not exist
return new ResponseEntity<JSONObject>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
if (session.getParticipants().isEmpty()) {
// Session has no participants
return new ResponseEntity<JSONObject>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
if (!(session.getSessionProperties().mediaMode().equals(MediaMode.ROUTED))
|| this.recordingService.sessionIsBeingRecorded(session.getSessionId())) {
// 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;
@ -253,7 +254,7 @@ public class SessionRestController {
if (recordingId == null) {
// "recordingId" parameter not found
return new ResponseEntity<JSONObject>(HttpStatus.BAD_REQUEST);
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Recording recording = recordingService.getStartedRecording(recordingId);
@ -261,14 +262,14 @@ public class SessionRestController {
if (recording == null) {
if (recordingService.getStartingRecording(recordingId) != null) {
// Recording is still starting
return new ResponseEntity<JSONObject>(HttpStatus.NOT_ACCEPTABLE);
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
}
// Recording does not exist
return new ResponseEntity<JSONObject>(HttpStatus.NOT_FOUND);
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
if (!this.recordingService.sessionIsBeingRecorded(recording.getSessionId())) {
// Session is not being recorded
return new ResponseEntity<JSONObject>(HttpStatus.CONFLICT);
return new ResponseEntity<>(HttpStatus.CONFLICT);
}
Session session = sessionManager.getSession(recording.getSessionId());
@ -327,6 +328,6 @@ public class SessionRestController {
responseJson.put("error", status.getReasonPhrase());
responseJson.put("message", errorMessage);
responseJson.put("path", path);
return new ResponseEntity<JSONObject>(responseJson, status);
return new ResponseEntity<>(responseJson, status);
}
}