Search in sources :

Example 1 with ServiceInvocationException

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;
}
Also used : Serializable(java.io.Serializable) ServiceNameVersion(i5.las2peer.api.p2p.ServiceNameVersion) Question(i5.las2peer.services.noracleService.model.Question)

Example 2 with ServiceInvocationException

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;
}
Also used : Serializable(java.io.Serializable) ServiceNameVersion(i5.las2peer.api.p2p.ServiceNameVersion) VoteList(i5.las2peer.services.noracleService.model.VoteList) InternalServiceException(i5.las2peer.api.execution.InternalServiceException)

Example 3 with ServiceInvocationException

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;
}
Also used : Serializable(java.io.Serializable) Vote(i5.las2peer.services.noracleService.model.Vote) ServiceNameVersion(i5.las2peer.api.p2p.ServiceNameVersion) InternalServiceException(i5.las2peer.api.execution.InternalServiceException)

Example 4 with ServiceInvocationException

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());
}
Also used : JSONObject(net.minidev.json.JSONObject) Gson(com.google.gson.Gson) JSONParser(net.minidev.json.parser.JSONParser) ParseException(net.minidev.json.parser.ParseException) ServiceInvocationException(i5.las2peer.api.execution.ServiceInvocationException) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with ServiceInvocationException

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;
}
Also used : Serializable(java.io.Serializable) Vote(i5.las2peer.services.noracleService.model.Vote) ServiceNameVersion(i5.las2peer.api.p2p.ServiceNameVersion) InternalServiceException(i5.las2peer.api.execution.InternalServiceException)

Aggregations

EnvelopeAccessDeniedException (i5.las2peer.api.persistency.EnvelopeAccessDeniedException)19 EnvelopeOperationFailedException (i5.las2peer.api.persistency.EnvelopeOperationFailedException)19 Envelope (i5.las2peer.api.persistency.Envelope)17 EnvelopeNotFoundException (i5.las2peer.api.persistency.EnvelopeNotFoundException)16 ServiceNameVersion (i5.las2peer.api.p2p.ServiceNameVersion)15 Serializable (java.io.Serializable)13 InternalServiceException (i5.las2peer.api.execution.InternalServiceException)9 ApiResponses (io.swagger.annotations.ApiResponses)7 ServiceInvocationException (i5.las2peer.api.execution.ServiceInvocationException)6 Agent (i5.las2peer.api.security.Agent)6 AnonymousAgent (i5.las2peer.api.security.AnonymousAgent)6 Gson (com.google.gson.Gson)5 Question (i5.las2peer.services.noracleService.model.Question)5 Space (i5.las2peer.services.noracleService.model.Space)5 Vote (i5.las2peer.services.noracleService.model.Vote)5 JSONObject (net.minidev.json.JSONObject)5 JSONParser (net.minidev.json.parser.JSONParser)5 ParseException (net.minidev.json.parser.ParseException)5 SpaceSubscription (i5.las2peer.services.noracleService.model.SpaceSubscription)4 SerializationException (i5.las2peer.serialization.SerializationException)3