use of fi.foyt.coops.model.Join in project muikku by otavanopisto.
the class CoOpsApiImpl method fileJoin.
public Join fileJoin(String fileId, List<String> algorithms, String protocolVersion) throws CoOpsNotFoundException, CoOpsNotImplementedException, CoOpsInternalErrorException, CoOpsForbiddenException, CoOpsUsageException {
HtmlMaterial htmlMaterial = findFile(fileId);
if (!COOPS_PROTOCOL_VERSION.equals(protocolVersion)) {
throw new CoOpsNotImplementedException("Protocol version mismatch. Client is using " + protocolVersion + " and server " + COOPS_PROTOCOL_VERSION);
}
if (algorithms == null || algorithms.isEmpty()) {
throw new CoOpsInternalErrorException("Invalid request");
}
CoOpsDiffAlgorithm algorithm = htmlMaterialController.findAlgorithm(algorithms);
if (algorithm == null) {
throw new CoOpsNotImplementedException("Server and client do not have a commonly supported algorithm.");
}
Long currentRevision = htmlMaterialController.lastHtmlMaterialRevision(htmlMaterial);
String data = htmlMaterialController.getRevisionHtml(htmlMaterial, currentRevision);
if (data == null) {
data = "";
}
Map<String, String> properties = htmlMaterialController.getRevisionProperties(htmlMaterial, currentRevision);
// TODO: Extension properties...
Map<String, Object> extensions = new HashMap<>();
String sessionId = UUID.randomUUID().toString();
CoOpsSession coOpsSession = coOpsSessionController.createSession(htmlMaterial, sessionController.getLoggedUserEntity(), sessionId, currentRevision, algorithm.getName());
addSessionEventsExtension(htmlMaterial, extensions);
addWebSocketExtension(htmlMaterial, extensions, coOpsSession);
return new Join(coOpsSession.getSessionId(), coOpsSession.getAlgorithm(), coOpsSession.getJoinRevision(), data, htmlMaterial.getContentType(), properties, extensions);
}
Aggregations