public Task<HttpResponse> build(final String hash, final InputStream body)
      throws IOException {
    if (hash == null) {
      // Missing hash
      String content = "Missing hash.";
      LOG.info(content);
      return Task.value(new HttpResponse(HttpServletResponse.SC_BAD_REQUEST, content));
    } else {
      // Have cache
      if (_hashManager.contains(hash)) {
        LOG.info("hash found in cache: " + hash);
        return Task.value(new HttpResponse(HttpServletResponse.SC_OK, ""));
      } else {
        if (body == null) {
          // Missing body
          String content = "Missing body.";
          LOG.info(content);
          return Task.value(new HttpResponse(HttpServletResponse.SC_BAD_REQUEST, content));
        } else if (_dotLocation == null) {
          // Missing dot
          String content = "Missing dot.";
          LOG.info(content);
          return Task.value(new HttpResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, content));
        } else {
          // Build task
          final Task<Exec.Result> buildTask = getBuildTask(hash, body);
          return buildTask.transform("result", result -> {
            Integer status = null;
            String content = null;
            if (result.isFailed()) {
              // Task fail
              status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
              content = result.getError().toString();
            } else {
              // Task success
              switch (result.get().getStatus()) {
                // Success
                case 0:
                  _hashManager.add(hash);
                  status = HttpServletResponse.SC_OK;
                  content = "";
                  break;
                // Timeout
                case 137:
                  status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                  content = "graphviz process was killed because it did not finish within " + _timeoutMs + "ms";
                  break;
                // Unknown
                default:
                  status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                  content = writeGenericFailureInfo(result.get());
                  break;
              }
            }
            // Clean up cache
            _inFlightBuildTasks.remove(hash, buildTask);
            return Success.of(new HttpResponse(status, content));
          });
        }
      }
    }
  }
public Task<HttpResponse> build(final String hash, final InputStream body)
      throws IOException {
    if (hash == null) {
      
      String content = "Missing hash.";
      LOG.info(content);
      return Task.value(new HttpResponse(HttpServletResponse.SC_BAD_REQUEST, content));
    } else {
      
      if (_hashManager.contains(hash)) {
        LOG.info("hash found in cache: " + hash);
        return Task.value(new HttpResponse(HttpServletResponse.SC_OK, ""));
      } else {
        if (body == null) {
          
          String content = "Missing body.";
          LOG.info(content);
          return Task.value(new HttpResponse(HttpServletResponse.SC_BAD_REQUEST, content));
        } else if (_dotLocation == null) {
          
          String content = "Missing dot.";
          LOG.info(content);
          return Task.value(new HttpResponse(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, content));
        } else {
          
          final Task<Exec.Result> buildTask = getBuildTask(hash, body);
          return buildTask.transform("result", result -> {
            Integer status = null;
            String content = null;
            if (result.isFailed()) {
              
              status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
              content = result.getError().toString();
            } else {
              
              switch (result.get().getStatus()) {
                
                case 0:
                  _hashManager.add(hash);
                  status = HttpServletResponse.SC_OK;
                  content = "";
                  break;
                
                case 137:
                  status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                  content = "graphviz process was killed because it did not finish within " + _timeoutMs + "ms";
                  break;
                
                default:
                  status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
                  content = writeGenericFailureInfo(result.get());
                  break;
              }
            }
            
            _inFlightBuildTasks.remove(hash, buildTask);
            return Success.of(new HttpResponse(status, content));
          });
        }
      }
    }
  }
public Task < HttpResponse > build ( final String hash , final InputStream body ) throws IOException { if ( hash == null ) { // Missing hash String content = "Missing hash." ; LOG . info ( content ) ; return Task . value ( new HttpResponse ( HttpServletResponse . SC_BAD_REQUEST , content ) ) ; } else { // Have cache if ( _hashManager . contains ( hash ) ) { LOG . info ( "hash found in cache: " + hash ) ; return Task . value ( new HttpResponse ( HttpServletResponse . SC_OK , "" ) ) ; } else { if ( body == null ) { // Missing body String content = "Missing body." ; LOG . info ( content ) ; return Task . value ( new HttpResponse ( HttpServletResponse . SC_BAD_REQUEST , content ) ) ; } else if ( _dotLocation == null ) { // Missing dot String content = "Missing dot." ; LOG . info ( content ) ; return Task . value ( new HttpResponse ( HttpServletResponse . SC_INTERNAL_SERVER_ERROR , content ) ) ; } else { // Build task final Task < Exec . Result > buildTask = getBuildTask ( hash , body ) ; return buildTask . transform ( "result" , result -> { Integer status = null ; String content = null ; if ( result . isFailed ( ) ) { // Task fail status = HttpServletResponse . SC_INTERNAL_SERVER_ERROR ; content = result . getError ( ) . toString ( ) ; } else { // Task success switch ( result . get ( ) . getStatus ( ) ) { // Success case 0 : _hashManager . add ( hash ) ; status = HttpServletResponse . SC_OK ; content = "" ; break ; // Timeout case 137 : status = HttpServletResponse . SC_INTERNAL_SERVER_ERROR ; content = "graphviz process was killed because it did not finish within " + _timeoutMs + "ms" ; break ; // Unknown default : status = HttpServletResponse . SC_INTERNAL_SERVER_ERROR ; content = writeGenericFailureInfo ( result . get ( ) ) ; break ; } } // Clean up cache _inFlightBuildTasks . remove ( hash , buildTask ) ; return Success . of ( new HttpResponse ( status , content ) ) ; } ) ; } } } }
Return task that has general HTTP status and body information based on the build task's result.
Return task that has general HTTP status and body information based on the build task s result .