Search in sources :

Example 1 with Join

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);
}
Also used : CoOpsNotImplementedException(fi.foyt.coops.CoOpsNotImplementedException) CoOpsSession(fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession) CoOpsInternalErrorException(fi.foyt.coops.CoOpsInternalErrorException) HashMap(java.util.HashMap) Join(fi.foyt.coops.model.Join) HtmlMaterial(fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)

Aggregations

CoOpsInternalErrorException (fi.foyt.coops.CoOpsInternalErrorException)1 CoOpsNotImplementedException (fi.foyt.coops.CoOpsNotImplementedException)1 Join (fi.foyt.coops.model.Join)1 CoOpsSession (fi.otavanopisto.muikku.plugins.material.coops.model.CoOpsSession)1 HtmlMaterial (fi.otavanopisto.muikku.plugins.material.model.HtmlMaterial)1 HashMap (java.util.HashMap)1