Java 类play.mvc.Results 实例源码

项目:pcs-storage-adapter-java    文件:ErrorHandler.java   
public CompletionStage<Result> onClientError(RequestHeader request, int statusCode, String message) {
    String errorMessage;
    switch (statusCode) {
        case 400:
            errorMessage = "BadRequest";
            break;
        case 403:
            errorMessage = "Forbidden";
            break;
        case 404:
            errorMessage = "NotFound";
            break;
        default:
            errorMessage = "OtherClientError";
    }
    HashMap<String, Object> errorResult = new HashMap<String, Object>() {
        {
            put("Message", "Client error occurred.");
            put("ExceptionMessage", errorMessage);
        }
    };
    return CompletableFuture.completedFuture(
            Results.status(statusCode, toJson(errorResult))
    );
}
项目:sunbird-lms-service    文件:BaseController.java   
/**
 * This method will create common response for all controller method
 * 
 * @param response Object
 * @param key String
 * @param request play.mvc.Http.Request
 * @return Result
 */
public Result createCommonResponse(Object response, String key, play.mvc.Http.Request request) {

  if (response instanceof Response) {
    Response courseResponse = (Response) response;
    if (!ProjectUtil.isStringNullOREmpty(key)) {
      Object value = courseResponse.getResult().get(JsonKey.RESPONSE);
      courseResponse.getResult().remove(JsonKey.RESPONSE);
      courseResponse.getResult().put(key, value);
    }
    return Results.ok(
        Json.toJson(BaseController.createSuccessResponse(request, (Response) courseResponse)));
  } else {
    ProjectCommonException exception = (ProjectCommonException) response;
    return Results.status(exception.getResponseCode(),
        Json.toJson(BaseController.createResponseOnException(request, exception)));
  }
}
项目:exam    文件:SystemErrorHandler.java   
@Override
public CompletionStage<Result> onClientError(Http.RequestHeader request, int statusCode, String message) {
    return CompletableFuture.supplyAsync(() -> {
        Logger.warn("onClientError: URL: {}, status: {}, msg: {}", request.uri(), statusCode, message);
        if (statusCode == play.mvc.Http.Status.BAD_REQUEST) {
            return Results.badRequest(Json.toJson(new ApiError(message)));
        }
        if (statusCode == play.mvc.Http.Status.NOT_FOUND) {
            return Results.notFound(Json.toJson(new ApiError(message)));
        }
        if (statusCode == Http.Status.UNAUTHORIZED || statusCode == Http.Status.FORBIDDEN) {
            return Results.unauthorized(Json.toJson(new ApiError(message)));
        }
        return Results.internalServerError(Json.toJson(new ApiError(message)));
    });
}
项目:exam    文件:SystemErrorHandler.java   
@Override
public CompletionStage<Result> onServerError(Http.RequestHeader request, Throwable exception) {
    return CompletableFuture.supplyAsync(() -> {
        Throwable cause = exception.getCause();
        String errorMessage = cause == null ? exception.getMessage() : cause.getMessage();
        Logger.error("onServerError: URL: {}, msg: {}", request.uri(), errorMessage);
        exception.printStackTrace();
        if (cause != null) {
            if (cause instanceof MalformedDataException) {
                return Results.badRequest(Json.toJson(errorMessage));
            }
            if (cause instanceof IllegalArgumentException) {
                return Results.badRequest(Json.toJson(new ApiError(errorMessage)));
            }
            if (cause instanceof OptimisticLockException) {
                return Results.badRequest("sitnet_error_data_has_changed");
            }
        }
        return Results.internalServerError(Json.toJson(new ApiError(errorMessage)));
    });
}
项目:assistance-platform-server    文件:CustomAssistanceProxy.java   
private Promise<Result> custom(
        String moduleId,
        String path,
        Function<WSRequest, Promise<WSResponse>> prepareAndFireRequest) {
    long userId = getUserIdForRequest();

    if (!UserModuleActivationPersistency.doesActivationExist(userId,
            moduleId)) {
        return Promise
                .pure(badRequestJson(AssistanceAPIErrors.moduleActivationNotActive));
    }

    ActiveAssistanceModule module = UserModuleActivationPersistency.activatedModuleEndpointsForUser(new String[]{moduleId})[0];

    WSRequest request = WS.url(module.restUrl("/custom/" + path));
    request.setHeader("ASSISTANCE-USER-ID", Long.toString(userId));
    Promise<WSResponse> responsePromise = prepareAndFireRequest.apply(request);

    return responsePromise.map((response) -> (Result) Results.status(response.getStatus(),
            response.getBody()));
}
项目:ground    文件:StructureController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructure() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Structure structure = Json.fromJson(json, Structure.class);

      try {
        structure = this.postgresStructureDao.create(structure);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(structure);
    },

    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:StructureController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addStructureVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");

      StructureVersion structureVersion = Json.fromJson(json, StructureVersion.class);

      try {
        structureVersion = this.postgresStructureVersionDao.create(structureVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(structureVersion);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:StructureController.java   
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "structure_leaves." + sourceKey,
          () -> Json.toJson(this.postgresStructureDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:StructureController.java   
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "structure_history." + sourceKey,
          () -> Json.toJson(this.postgresStructureDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
public final CompletionStage<Result> getLineageEdge(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edges." + sourceKey,
          () -> Json.toJson(this.postgresLineageEdgeDao.retrieveFromDatabase(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
public final CompletionStage<Result> getLineageEdgeVersion(Long id) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edge_versions." + id,
          () -> Json.toJson(this.postgresLineageEdgeVersionDao.retrieveFromDatabase(id)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageEdge() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      LineageEdge lineageEdge = Json.fromJson(json, LineageEdge.class);
      try {
        lineageEdge = this.postgresLineageEdgeDao.create(lineageEdge);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageEdge);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
public final CompletionStage<Result> createLineageEdgeVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");

      LineageEdgeVersion lineageEdgeVersion = Json.fromJson(json, LineageEdgeVersion.class);

      try {
        lineageEdgeVersion = this.postgresLineageEdgeVersionDao.create(lineageEdgeVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageEdgeVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edge_leaves." + sourceKey,
          () -> Json.toJson(this.postgresLineageEdgeDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageEdgeController.java   
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_edge_history." + sourceKey,
          () -> Json.toJson(this.postgresLineageEdgeDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
public final CompletionStage<Result> getLineageGraph(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_graphs." + sourceKey,
          () -> Json.toJson(this.postgresLineageGraphDao.retrieveFromDatabase(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
public final CompletionStage<Result> getLineageGraphVersion(Long id) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_graph_versions." + id,
          () -> Json.toJson(this.postgresLineageGraphVersionDao.retrieveFromDatabase(id)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> createLineageGraph() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      LineageGraph lineageGraph = Json.fromJson(json, LineageGraph.class);
      try {
        lineageGraph = this.postgresLineageGraphDao.create(lineageGraph);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageGraph);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
public final CompletionStage<Result> createLineageGraphVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");

      LineageGraphVersion lineageGraphVersion = Json.fromJson(json, LineageGraphVersion.class);

      try {
        lineageGraphVersion = this.postgresLineageGraphVersionDao.create(lineageGraphVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(lineageGraphVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_graph_leaves." + sourceKey,
          () -> Json.toJson(this.postgresLineageGraphDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:LineageGraphController.java   
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "lineage_graph_history." + sourceKey,
          () -> Json.toJson(this.postgresLineageGraphDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
public final CompletionStage<Result> getGraph(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "graphs." + sourceKey,
          () -> Json.toJson(this.postgresGraphDao.retrieveFromDatabase(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraph() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Graph graph = Json.fromJson(json, Graph.class);

      try {
        graph = this.postgresGraphDao.create(graph);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }

      return Json.toJson(graph);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addGraphVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");
      GraphVersion graphVersion = Json.fromJson(json, GraphVersion.class);

      try {
        graphVersion = this.postgresGraphVersionDao.create(graphVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(graphVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "graph_leaves." + sourceKey,
          () -> Json.toJson(this.postgresGraphDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:GraphController.java   
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "graph_history." + sourceKey,
          () -> Json.toJson(this.postgresGraphDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
public final CompletionStage<Result> getEdge(final String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "edges." + sourceKey,
          () -> Json.toJson(this.postgresEdgeDao.retrieveFromDatabase(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addEdge() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Edge edge = Json.fromJson(json, Edge.class);

      try {
        edge = this.postgresEdgeDao.create(edge);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }

      return Json.toJson(edge);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
public final CompletionStage<Result> getEdgeVersion(Long id) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "edge_versions." + id,
          () -> Json.toJson(this.postgresEdgeVersionDao.retrieveFromDatabase(id)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addEdgeVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");

      ((ObjectNode) json).remove("parentIds");
      EdgeVersion edgeVersion = Json.fromJson(json, EdgeVersion.class);

      try {
        edgeVersion = this.postgresEdgeVersionDao.create(edgeVersion, parentIds);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }

      return Json.toJson(edgeVersion);
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "edge_leaves." + sourceKey,
          () -> Json.toJson(this.postgresEdgeDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:EdgeController.java   
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "edge_history." + sourceKey,
          () -> Json.toJson(this.postgresEdgeDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
public final CompletionStage<Result> getNode(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "nodes." + sourceKey,
          () -> Json.toJson(this.postgresNodeDao.retrieveFromDatabase(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addNode() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();
      Node node = Json.fromJson(json, Node.class);
      try {
        node = this.postgresNodeDao.create(node);
      } catch (GroundException e) {
        throw new CompletionException(e);
      }
      return Json.toJson(node);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
public final CompletionStage<Result> getNodeVersion(Long id) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "node_versions." + id,
          () -> Json.toJson(this.postgresNodeVersionDao.retrieveFromDatabase(id)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
@BodyParser.Of(BodyParser.Json.class)
public final CompletionStage<Result> addNodeVersion() {
  return CompletableFuture.supplyAsync(
    () -> {
      JsonNode json = request().body().asJson();

      List<Long> parentIds = GroundUtils.getListFromJson(json, "parentIds");
      ((ObjectNode) json).remove("parentIds");
      NodeVersion nodeVersion = Json.fromJson(json, NodeVersion.class);

      try {
        nodeVersion = this.postgresNodeVersionDao.create(nodeVersion, parentIds);
      } catch (GroundException e) {
        e.printStackTrace();
        throw new CompletionException(e);
      }
      return Json.toJson(nodeVersion);
    },
    PostgresUtils.getDbSourceHttpContext(this.actorSystem))
           .thenApply(Results::created)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
public final CompletionStage<Result> getLatest(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "node_leaves." + sourceKey,
          () -> Json.toJson(this.postgresNodeDao.getLeaves(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
public final CompletionStage<Result> getHistory(String sourceKey) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "node_history." + sourceKey,
          () -> Json.toJson(this.postgresNodeDao.getHistory(sourceKey)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:ground    文件:NodeController.java   
public final CompletionStage<Result> getAdjacentLineage(Long id) {
  return CompletableFuture.supplyAsync(
    () -> {
      try {
        return this.cache.getOrElse(
          "node_version_adj_lineage." + id,
          () -> Json.toJson(this.postgresNodeVersionDao.retrieveAdjacentLineageEdgeVersion(id)),
          Integer.parseInt(System.getProperty("ground.cache.expire.secs")));
      } catch (Exception e) {
        throw new CompletionException(e);
      }
    },
    PostgresUtils.getDbSourceHttpContext(actorSystem))
           .thenApply(Results::ok)
           .exceptionally(e -> GroundUtils.handleException(e, request()));
}
项目:activator-lagom-cargotracker    文件:ErrorHandler.java   
/**
 * Invoked in dev mode when a server error occurs.
 *
 * @param request The request that triggered the error.
 * @param exception The exception.
 */
protected CompletionStage<Result> onDevServerError(Http.RequestHeader request, UsefulException exception) {

    ObjectNode jsonError = Json.newObject();

    final Throwable cause = exception.cause;
    final String description = exception.description;
    final String id = exception.id;
    final String title = exception.title;

    jsonError.put("description", description);
    jsonError.put("title", title);
    jsonError.put("id", id);
    jsonError.put("message", exception.getMessage());
    jsonError.set("cause", causesToJson(cause));

    return CompletableFuture.completedFuture(Results.internalServerError(jsonError));
}