From a0e50d1022f310e269effc4a235dd361d7136df1 Mon Sep 17 00:00:00 2001 From: pabloFuente Date: Wed, 4 Jul 2018 12:54:27 +0200 Subject: [PATCH] openvidu-server: REST controller cleaned up --- .../server/rest/SessionRestController.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java index ab1e288b..cbd310d5 100644 --- a/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java +++ b/openvidu-server/src/main/java/io/openvidu/server/rest/SessionRestController.java @@ -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(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 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 listSessions(@RequestParam("webRtcStats") boolean webRtcStats) { + public ResponseEntity listSessions( + @RequestParam(value = "webRtcStats", defaultValue = "false", required = false) boolean webRtcStats) { Collection 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(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(HttpStatus.NOT_IMPLEMENTED); + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } Session session = sessionManager.getSession(sessionId); if (session == null) { // Session does not exist - return new ResponseEntity(HttpStatus.NOT_FOUND); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (session.getParticipants().isEmpty()) { // Session has no participants - return new ResponseEntity(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(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(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(HttpStatus.NOT_ACCEPTABLE); + return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE); } // Recording does not exist - return new ResponseEntity(HttpStatus.NOT_FOUND); + return new ResponseEntity<>(HttpStatus.NOT_FOUND); } if (!this.recordingService.sessionIsBeingRecorded(recording.getSessionId())) { // Session is not being recorded - return new ResponseEntity(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(responseJson, status); + return new ResponseEntity<>(responseJson, status); } }