Search in sources :

Example 1 with InternalServiceException

use of i5.las2peer.api.execution.InternalServiceException 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 2 with InternalServiceException

use of i5.las2peer.api.execution.InternalServiceException 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 3 with InternalServiceException

use of i5.las2peer.api.execution.InternalServiceException 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)

Example 4 with InternalServiceException

use of i5.las2peer.api.execution.InternalServiceException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleAgentService method unsubscribeFromSpace.

@Override
public void unsubscribeFromSpace(String spaceId) throws ServiceInvocationException {
    Agent mainAgent = Context.get().getMainAgent();
    if (spaceId == null || spaceId.isEmpty()) {
        throw new InvocationBadArgumentException("No space id given");
    } else if (mainAgent instanceof AnonymousAgent) {
        throw new ServiceAccessDeniedException("You have to be logged in to unsubscribe to a space");
    }
    String envIdentifier = buildSubscriptionId(mainAgent.getIdentifier());
    Envelope env;
    SpaceSubscriptionList subscriptionList;
    try {
        try {
            env = Context.get().requestEnvelope(envIdentifier);
            subscriptionList = (SpaceSubscriptionList) env.getContent();
        } catch (EnvelopeNotFoundException e) {
            return;
        }
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not read envelope for space unsubscription", e);
    }
    Iterator<SpaceSubscription> itSubscription = subscriptionList.iterator();
    while (itSubscription.hasNext()) {
        SpaceSubscription subscription = itSubscription.next();
        if (subscription.getSpaceId().equals(spaceId)) {
            itSubscription.remove();
        }
    }
    env.setContent(subscriptionList);
    try {
        Context.get().storeEnvelope(env, mainAgent);
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not store space subscription envelope", e);
    }
}
Also used : AnonymousAgent(i5.las2peer.api.security.AnonymousAgent) Agent(i5.las2peer.api.security.Agent) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) AnonymousAgent(i5.las2peer.api.security.AnonymousAgent) SpaceSubscriptionList(i5.las2peer.services.noracleService.model.SpaceSubscriptionList) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) SpaceSubscription(i5.las2peer.services.noracleService.model.SpaceSubscription)

Example 5 with InternalServiceException

use of i5.las2peer.api.execution.InternalServiceException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleQuestionService method createQuestion.

@Override
public Question createQuestion(String questionSpaceId, String text) throws ServiceInvocationException {
    Agent mainAgent = Context.get().getMainAgent();
    if (questionSpaceId == null || questionSpaceId.isEmpty()) {
        throw new InvocationBadArgumentException("No question space id given");
    } else if (text == null || text.isEmpty()) {
        throw new InvocationBadArgumentException("No question text given");
    } else if (mainAgent instanceof AnonymousAgent) {
        throw new ServiceNotAuthorizedException("You have to be logged in to create a question");
    }
    Space targetSpace;
    Serializable rmiResult = Context.get().invoke(new ServiceNameVersion(NoracleSpaceService.class.getCanonicalName(), NoracleService.API_VERSION), "getSpace", questionSpaceId);
    if (rmiResult instanceof Space) {
        targetSpace = (Space) rmiResult;
    } else {
        throw new InternalServiceException("Unexpected result (" + rmiResult.getClass().getCanonicalName() + ") of RMI call");
    }
    String targetReaderGroupId = targetSpace.getSpaceReaderGroupId();
    GroupAgent targetReaderGroup;
    try {
        targetReaderGroup = (GroupAgent) Context.get().requestAgent(targetReaderGroupId, mainAgent);
    } catch (AgentNotFoundException | AgentOperationFailedException e) {
        throw new InternalServiceException("Could not fetch reader group agent for space", e);
    } catch (ClassCastException e) {
        throw new InternalServiceException("Agent for space reader group is not a GroupAgent", e);
    } catch (AgentAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Agent not in space reader group", e);
    }
    String questionId = buildQuestionId();
    Envelope env;
    try {
        env = Context.get().createEnvelope(getQuestionEnvelopeIdentifier(questionId), mainAgent);
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not create envelope for question", e);
    }
    env.addReader(targetReaderGroup);
    Question question = new Question(questionId, text, questionSpaceId, mainAgent.getIdentifier(), Instant.now().toString());
    env.setContent(question);
    try {
        Context.get().storeEnvelope(env, mainAgent);
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not store question envelope", e);
    }
    if (questionSpaceId != null && !questionSpaceId.isEmpty()) {
        linkQuestionToSpace(questionSpaceId, questionId);
    }
    return question;
}
Also used : Space(i5.las2peer.services.noracleService.model.Space) Serializable(java.io.Serializable) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope) ServiceNameVersion(i5.las2peer.api.p2p.ServiceNameVersion) Question(i5.las2peer.services.noracleService.model.Question)

Aggregations

Envelope (i5.las2peer.api.persistency.Envelope)15 EnvelopeAccessDeniedException (i5.las2peer.api.persistency.EnvelopeAccessDeniedException)15 EnvelopeOperationFailedException (i5.las2peer.api.persistency.EnvelopeOperationFailedException)15 EnvelopeNotFoundException (i5.las2peer.api.persistency.EnvelopeNotFoundException)12 ServiceNameVersion (i5.las2peer.api.p2p.ServiceNameVersion)7 InternalServiceException (i5.las2peer.api.execution.InternalServiceException)6 Agent (i5.las2peer.api.security.Agent)6 AnonymousAgent (i5.las2peer.api.security.AnonymousAgent)6 Serializable (java.io.Serializable)6 Question (i5.las2peer.services.noracleService.model.Question)4 Space (i5.las2peer.services.noracleService.model.Space)4 Vote (i5.las2peer.services.noracleService.model.Vote)4 QuestionRelation (i5.las2peer.services.noracleService.model.QuestionRelation)3 SpaceSubscription (i5.las2peer.services.noracleService.model.SpaceSubscription)3 SpaceSubscriptionList (i5.las2peer.services.noracleService.model.SpaceSubscriptionList)3 VoteEntry (i5.las2peer.services.noracleService.model.VoteEntry)2 VoteList (i5.las2peer.services.noracleService.model.VoteList)2 InvocationBadArgumentException (i5.las2peer.api.execution.InvocationBadArgumentException)1 ServiceAccessDeniedException (i5.las2peer.api.execution.ServiceAccessDeniedException)1 ServiceInvocationException (i5.las2peer.api.execution.ServiceInvocationException)1