Search in sources :

Example 16 with EnvelopeNotFoundException

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

the class NoracleQuestionService method retrieveQuestion.

private boolean retrieveQuestion(QuestionList result, String spaceId, int questionNumber) throws EnvelopeNotFoundException {
    try {
        Envelope spaceQuestionEnv = Context.get().requestEnvelope(buildSpaceQuestionNumberId(spaceId, questionNumber));
        String questionId = (String) spaceQuestionEnv.getContent();
        Envelope questionEnv = Context.get().requestEnvelope(getQuestionEnvelopeIdentifier(questionId));
        Question question = (Question) questionEnv.getContent();
        // TODO check if author is a member of this space?
        // String authorId = question.getAuthorId();
        // if (authorId == null || authorId.isEmpty()) {
        // return false;
        // }
        result.add(question);
        return true;
    } catch (EnvelopeNotFoundException e) {
        throw e;
    } catch (Exception e) {
    // XXX logging
    }
    return false;
}
Also used : EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) Question(i5.las2peer.services.noracleService.model.Question) Envelope(i5.las2peer.api.persistency.Envelope) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException)

Example 17 with EnvelopeNotFoundException

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

the class NoracleSpaceService method getSpace.

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

Example 18 with EnvelopeNotFoundException

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

the class NoracleQuestionRelationService method getQuestionRelation.

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

Example 19 with EnvelopeNotFoundException

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

the class NoracleQuestionRelationService method linkQuestionRelationToSpace.

public boolean linkQuestionRelationToSpace(String spaceId, String relationId) {
    int relationNumber;
    for (relationNumber = 1; relationNumber < MAX_RELATIONS_PER_SPACE; relationNumber++) {
        try {
            Context.get().requestEnvelope(buildSpaceQuestionRelationNumberId(spaceId, relationNumber));
        } catch (EnvelopeNotFoundException e) {
            // found free question number
            break;
        } catch (Exception e) {
        // XXX logging
        }
    }
    try {
        Envelope spaceQuestionRelationEnv = Context.get().createEnvelope(buildSpaceQuestionRelationNumberId(spaceId, relationNumber));
        spaceQuestionRelationEnv.setPublic();
        spaceQuestionRelationEnv.setContent(relationId);
        Context.get().storeEnvelope(spaceQuestionRelationEnv);
        return true;
    } catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
        // TODO exception handling
        e.printStackTrace();
    }
    return false;
}
Also used : EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException)

Example 20 with EnvelopeNotFoundException

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

the class NoracleVoteService method getAgentVote.

@Override
public Vote getAgentVote(String objectId, String agentId) throws ServiceInvocationException {
    String persEnvId = getAgentVoteEnvelopeIdentifier(agentId, objectId);
    try {
        Envelope persEnv = Context.get().requestEnvelope(persEnvId);
        VoteEntry voteEntry = (VoteEntry) persEnv.getContent();
        return voteEntry.getVote();
    } catch (EnvelopeAccessDeniedException e) {
        throw new InternalServiceException("Someone hijacked your vote envelope", e);
    } catch (EnvelopeNotFoundException e) {
        return new Vote(0, agentId);
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Retrieving vote failed", e);
    }
}
Also used : Vote(i5.las2peer.services.noracleService.model.Vote) VoteEntry(i5.las2peer.services.noracleService.model.VoteEntry) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope) InternalServiceException(i5.las2peer.api.execution.InternalServiceException)

Aggregations

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