use of i5.las2peer.services.noracleService.model.VoteList in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionsResource method getQuestionsWeb.
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "A list of questions from the network", response = QuestionList.class), @ApiResponse(code = HttpURLConnection.HTTP_BAD_REQUEST, message = "No space id given", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_FORBIDDEN, message = "Access Denied", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Server Error", response = ExceptionEntity.class) })
public Response getQuestionsWeb(@PathParam("spaceId") String spaceId, @QueryParam("order") String order, @QueryParam("limit") Integer limit, @QueryParam("startat") Integer startAt) throws ServiceInvocationException {
QuestionList questionList = getQuestions(spaceId, order, limit, startAt);
VotedQuestionList votedQuestionList = new VotedQuestionList();
for (Question question : questionList) {
VotedQuestion votedQuestion = new VotedQuestion(question);
String objectId = QuestionVotesResource.buildObjectId(spaceId, question.getQuestionId());
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleVoteService.class.getCanonicalName(), NoracleService.API_VERSION), "getAllVotes", objectId);
if (rmiResult instanceof VoteList) {
votedQuestion.setVotes((VoteList) rmiResult);
}
votedQuestionList.add(votedQuestion);
}
ResponseBuilder responseBuilder = Response.ok(votedQuestionList);
String queryOrder = order != null ? "order=" + order : "";
String queryLimit = limit != null ? "limit=" + Integer.toString(limit) : "";
String queryStartAt = "";
if (startAt != null && limit != null) {
if (order.equalsIgnoreCase("desc")) {
queryStartAt = "startat=" + Integer.toString(startAt - limit);
} else {
queryStartAt = "startat=" + Integer.toString(startAt + limit);
}
}
String nextLinkStr = "";
for (String param : new String[] { queryOrder, queryLimit, queryStartAt }) {
if (param != null && !param.isEmpty()) {
if (nextLinkStr.isEmpty()) {
nextLinkStr += "?";
} else {
nextLinkStr += "&";
}
nextLinkStr += param;
}
}
if (!nextLinkStr.isEmpty()) {
responseBuilder.header(HttpHeaders.LINK, "<" + nextLinkStr + ">; rel=\"next\"");
}
return responseBuilder.build();
}
Aggregations