Search in sources :

Example 6 with EnvelopeOperationFailedException

use of i5.las2peer.api.persistency.EnvelopeOperationFailedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleQuestionService method getQuestion.

@Override
public Question getQuestion(String questionId) throws ServiceInvocationException {
    if (questionId == null || questionId.isEmpty()) {
        throw new InvocationBadArgumentException("No question id given");
    }
    Envelope env;
    try {
        env = Context.get().requestEnvelope(getQuestionEnvelopeIdentifier(questionId));
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not fetch question envelope", e);
    } catch (EnvelopeNotFoundException e) {
        throw new ResourceNotFoundException("Question Not Found");
    }
    Question question = (Question) env.getContent();
    return question;
}
Also used : EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) Question(i5.las2peer.services.noracleService.model.Question) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope)

Example 7 with EnvelopeOperationFailedException

use of i5.las2peer.api.persistency.EnvelopeOperationFailedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method getMemberAgent.

private GroupAgent getMemberAgent(String spaceId) throws EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException, AgentNotFoundException, AgentOperationFailedException {
    String memberAgentEnvelopeId = getMemberMappingIdentifier(spaceId);
    Envelope memberAgentMapping = Context.get().requestEnvelope(memberAgentEnvelopeId);
    String memberAgentId = (String) memberAgentMapping.getContent();
    GroupAgent memberAgent = (GroupAgent) Context.get().fetchAgent(memberAgentId);
    return memberAgent;
}
Also used : Envelope(i5.las2peer.api.persistency.Envelope)

Example 8 with EnvelopeOperationFailedException

use of i5.las2peer.api.persistency.EnvelopeOperationFailedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method getInviteAgent.

private UserAgentImpl getInviteAgent(String spaceId) throws AgentNotFoundException, AgentOperationFailedException, EnvelopeAccessDeniedException, EnvelopeNotFoundException, EnvelopeOperationFailedException {
    String inviteAgentEnvelopeId = getInviteMappingIdentifier(spaceId);
    Envelope inviteAgentMapping = Context.get().requestEnvelope(inviteAgentEnvelopeId);
    String inviteAgentId = (String) inviteAgentMapping.getContent();
    UserAgentImpl inviteAgent = (UserAgentImpl) Context.get().fetchAgent(inviteAgentId);
    return inviteAgent;
}
Also used : Envelope(i5.las2peer.api.persistency.Envelope) UserAgentImpl(i5.las2peer.security.UserAgentImpl)

Example 9 with EnvelopeOperationFailedException

use of i5.las2peer.api.persistency.EnvelopeOperationFailedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleVoteService method setVote.

@Override
public Vote setVote(String agentId, String objectId, int vote) throws ServiceInvocationException {
    Agent mainAgent = Context.get().getMainAgent();
    if (objectId == null || objectId.isEmpty()) {
        throw new InvocationBadArgumentException("No object id given");
    } else if (mainAgent instanceof AnonymousAgent) {
        throw new ServiceAccessDeniedException("You have to be logged in to vote");
    }
    String persEnvId = getAgentVoteEnvelopeIdentifier(agentId, objectId);
    try {
        try {
            Envelope persEnv = Context.get().requestEnvelope(persEnvId);
            VoteEntry voteEntry = (VoteEntry) persEnv.getContent();
            int pubIndex = voteEntry.getPubIndex();
            String pubEnvId = getPublicVoteEnvelopeIdentifier(objectId, pubIndex);
            Vote pubVote = updateOrCreatePubVoteEnv(pubEnvId, vote, mainAgent.getIdentifier());
            voteEntry = (VoteEntry) persEnv.getContent();
            voteEntry.setVote(pubVote);
            persEnv.setContent(voteEntry);
            Context.get().storeEnvelope(persEnv);
            return pubVote;
        } catch (EnvelopeNotFoundException e) {
            Envelope persEnv = Context.get().createEnvelope(persEnvId);
            String pubEnvId = null;
            int pubIndex = -1;
            for (int num = 1; num < MAX_VOTES_PER_OBJECT; num++) {
                try {
                    pubEnvId = getPublicVoteEnvelopeIdentifier(objectId, num);
                    Context.get().requestEnvelope(pubEnvId);
                } catch (EnvelopeNotFoundException e2) {
                    // found non taken vote index
                    pubIndex = num;
                    break;
                } catch (Exception e2) {
                // XXX logging
                }
            }
            if (pubEnvId == null || pubEnvId.isEmpty()) {
                throw new InternalServiceException("Public envelope id is null");
            } else if (pubIndex == -1) {
                throw new InternalServiceException("Too many votes for this object");
            }
            Vote pubVote = updateOrCreatePubVoteEnv(pubEnvId, vote, mainAgent.getIdentifier());
            VoteEntry voteEntry = new VoteEntry(objectId, pubIndex, pubVote);
            persEnv.setContent(voteEntry);
            Context.get().storeEnvelope(persEnv);
            return pubVote;
        }
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not create envelope for vote", e);
    }
}
Also used : AnonymousAgent(i5.las2peer.api.security.AnonymousAgent) Agent(i5.las2peer.api.security.Agent) Vote(i5.las2peer.services.noracleService.model.Vote) VoteEntry(i5.las2peer.services.noracleService.model.VoteEntry) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) InvocationBadArgumentException(i5.las2peer.api.execution.InvocationBadArgumentException) AnonymousAgent(i5.las2peer.api.security.AnonymousAgent) ServiceAccessDeniedException(i5.las2peer.api.execution.ServiceAccessDeniedException) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) InvocationBadArgumentException(i5.las2peer.api.execution.InvocationBadArgumentException) ServiceAccessDeniedException(i5.las2peer.api.execution.ServiceAccessDeniedException) ServiceInvocationException(i5.las2peer.api.execution.ServiceInvocationException) InternalServiceException(i5.las2peer.api.execution.InternalServiceException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) InternalServiceException(i5.las2peer.api.execution.InternalServiceException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException)

Example 10 with EnvelopeOperationFailedException

use of i5.las2peer.api.persistency.EnvelopeOperationFailedException in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleVoteService method updateOrCreatePubVoteEnv.

private Vote updateOrCreatePubVoteEnv(String pubEnvId, int vote, String agentId) throws EnvelopeAccessDeniedException, EnvelopeOperationFailedException {
    Vote pubVote;
    try {
        Envelope pubEnv = Context.get().requestEnvelope(pubEnvId);
        pubVote = (Vote) pubEnv.getContent();
        pubVote.setValue(vote);
        pubEnv.setContent(pubVote);
        Context.get().storeEnvelope(pubEnv);
    } catch (EnvelopeNotFoundException e) {
        Envelope pubEnv = Context.get().createEnvelope(pubEnvId);
        pubEnv.setPublic();
        pubVote = new Vote(vote, agentId);
        pubEnv.setContent(pubVote);
        Context.get().storeEnvelope(pubEnv);
    }
    return pubVote;
}
Also used : Vote(i5.las2peer.services.noracleService.model.Vote) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) Envelope(i5.las2peer.api.persistency.Envelope)

Aggregations

Envelope (i5.las2peer.api.persistency.Envelope)20 EnvelopeAccessDeniedException (i5.las2peer.api.persistency.EnvelopeAccessDeniedException)17 EnvelopeOperationFailedException (i5.las2peer.api.persistency.EnvelopeOperationFailedException)17 EnvelopeNotFoundException (i5.las2peer.api.persistency.EnvelopeNotFoundException)15 Agent (i5.las2peer.api.security.Agent)6 AnonymousAgent (i5.las2peer.api.security.AnonymousAgent)6 Question (i5.las2peer.services.noracleService.model.Question)4 QuestionRelation (i5.las2peer.services.noracleService.model.QuestionRelation)3 Space (i5.las2peer.services.noracleService.model.Space)3 SpaceSubscription (i5.las2peer.services.noracleService.model.SpaceSubscription)3 SpaceSubscriptionList (i5.las2peer.services.noracleService.model.SpaceSubscriptionList)3 Vote (i5.las2peer.services.noracleService.model.Vote)3 InternalServiceException (i5.las2peer.api.execution.InternalServiceException)2 ServiceNameVersion (i5.las2peer.api.p2p.ServiceNameVersion)2 VoteEntry (i5.las2peer.services.noracleService.model.VoteEntry)2 InvocationBadArgumentException (i5.las2peer.api.execution.InvocationBadArgumentException)1 ServiceAccessDeniedException (i5.las2peer.api.execution.ServiceAccessDeniedException)1 ServiceInvocationException (i5.las2peer.api.execution.ServiceInvocationException)1 GroupAgentImpl (i5.las2peer.security.GroupAgentImpl)1 UserAgentImpl (i5.las2peer.security.UserAgentImpl)1