Ejemplo n.º 1
0
  private void putAssessment(Request request, Response response, String username) {
    try {
      NativeDocument doc = NativeDocumentFactory.newNativeDocument();
      doc.parse(request.getEntity().getText());
      AssessmentParser parser = new AssessmentParser(doc);
      AssessmentData assessment = parser.getAssessment();

      AssessmentIOWriteResult result = assignIDAndSave(assessment, username);
      if (result.status.isSuccess()) {
        response.setEntity(assessment.getAssessmentID(), MediaType.TEXT_PLAIN);
        response.setStatus(Status.SUCCESS_OK);
      } else {
        response.setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
      }
    } catch (RegionConflictException e) {
      response.setStatus(Status.CLIENT_ERROR_CONFLICT);
    } catch (Exception e) {
      response.setStatus(Status.SERVER_ERROR_INTERNAL);
    }
  }
Ejemplo n.º 2
0
  private void postAssessment(Request request, Response response, String username) {
    try {
      String entity = request.getEntity().getText();

      NativeDocument doc = NativeDocumentFactory.newNativeDocument();
      doc.parse(entity);
      AssessmentParser parser = new AssessmentParser(doc);
      AssessmentData assessment = parser.getAssessment();

      VFSPath assessmentUrl = new VFSPath(ServerPaths.getPathForAssessment(assessment, username));

      if (vfs.exists(assessmentUrl)) {
        Status status =
            FileLocker.impl.persistentLockAssessment(
                assessment.getAssessmentID(),
                BaseAssessment.DRAFT_ASSESSMENT_STATUS,
                LockType.SAVE_LOCK,
                username);

        if (status.isSuccess()) {
          AssessmentIOWriteResult result = saveAssessment(assessment, username);
          if (result.status.isSuccess()) {
            response.setEntity(result.newLastModified + "", MediaType.TEXT_PLAIN);
            response.setStatus(status);
          } else {
            response.setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
          }
        } else {
          response.setStatus(status);
        }
      }
    } catch (RegionConflictException e) {
      response.setStatus(Status.CLIENT_ERROR_CONFLICT);
    } catch (Exception e) {
      e.printStackTrace();
      response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
    }
  }