use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionVotesResource method getQuestionText.
private String getQuestionText(String questionId) throws ServiceInvocationException {
String qText = "";
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleQuestionService.class.getCanonicalName(), NoracleService.API_VERSION), "getQuestion", questionId);
if (rmiResult instanceof Question)
qText = ((Question) rmiResult).getText();
return qText;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionVotesResource method getAllVotes.
@Override
public VoteList getAllVotes(String objectId) throws ServiceInvocationException {
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleVoteService.class.getCanonicalName(), NoracleService.API_VERSION), "getAllVotes", objectId);
VoteList vote;
if (rmiResult instanceof VoteList) {
vote = (VoteList) rmiResult;
} else {
throw new InternalServiceException("Unexpected result (" + rmiResult.getClass().getCanonicalName() + ") of RMI call");
}
return vote;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionVotesResource method getAgentVote.
@Override
public Vote getAgentVote(String objectId, String agentId) throws ServiceInvocationException {
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleVoteService.class.getCanonicalName(), NoracleService.API_VERSION), "getAgentVote", objectId, agentId);
Vote vote;
if (rmiResult instanceof Vote) {
vote = (Vote) rmiResult;
} else {
throw new InternalServiceException("Unexpected result (" + rmiResult.getClass().getCanonicalName() + ") of RMI call");
}
return vote;
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class QuestionVotesResource method putSetQuestionVote.
@PUT
@Path("/{agentId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponse(code = HttpURLConnection.HTTP_OK, message = "Vote successfully set", response = Vote.class), @ApiResponse(code = HttpURLConnection.HTTP_UNAUTHORIZED, message = "You have to be logged in to vote", response = ExceptionEntity.class), @ApiResponse(code = HttpURLConnection.HTTP_INTERNAL_ERROR, message = "Internal Server Error", response = ExceptionEntity.class) })
public Vote putSetQuestionVote(@PathParam("spaceId") String spaceId, @PathParam("questionId") String questionId, @PathParam("agentId") String agentId, @ApiParam(required = true) SetVotePojo setVotePojo) throws ServiceInvocationException {
String objectId = buildObjectId(spaceId, questionId);
Gson gson = new Gson();
String voteJSON = gson.toJson(setVotePojo);
JSONParser p = new JSONParser(JSONParser.MODE_PERMISSIVE);
try {
JSONObject obj = (JSONObject) p.parse(voteJSON);
JSONObject attributes = new JSONObject();
obj.put("spaceId", spaceId);
obj.put("qId", questionId);
obj.put("functionName", "putSetQuestionVote");
obj.put("serviceAlias", "distributed-noracle");
obj.put("uid", Context.getCurrent().getMainAgent().getIdentifier());
attributes.put("spaceId", spaceId);
attributes.put("qId", questionId);
attributes.put("body", p.parse(voteJSON));
attributes.put("result", "");
obj.put("attributes", attributes);
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_7, obj.toJSONString());
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Try to log training data
try {
String from = getQuestionText(questionId);
Integer to = setVotePojo.getValue();
JSONObject trainingData = new JSONObject();
trainingData.put("unit", spaceId);
trainingData.put("from", from);
trainingData.put("to", to);
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_MESSAGE_47, trainingData.toString());
} catch (ServiceInvocationException e) {
Context.get().monitorEvent(MonitoringEvent.SERVICE_CUSTOM_ERROR_47, questionId);
}
return setVote(agentId, objectId, setVotePojo.getValue());
}
use of i5.las2peer.api.execution.ServiceInvocationException in project Distributed-Noracle-Backend by Distributed-Noracle.
the class RelationVotesResource method getAgentVote.
@Override
public Vote getAgentVote(String objectId, String agentId) throws ServiceInvocationException {
Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleVoteService.class.getCanonicalName(), NoracleService.API_VERSION), "getAgentVote", objectId, agentId);
Vote vote;
if (rmiResult instanceof Vote) {
vote = (Vote) rmiResult;
} else {
throw new InternalServiceException("Unexpected result (" + rmiResult.getClass().getCanonicalName() + ") of RMI call");
}
return vote;
}
Aggregations