Search in sources :

Example 1 with EnvelopeNotFoundException

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

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

the class NoracleQuestionService method changeQuestionDepth.

@Override
public Question changeQuestionDepth(String questionId, int depth) throws ServiceInvocationException {
    if (questionId == null) {
        throw new InvocationBadArgumentException("No question id given");
    }
    try {
        Envelope questionEnvelope = Context.get().requestEnvelope(getQuestionEnvelopeIdentifier(questionId));
        Question question = (Question) questionEnvelope.getContent();
        question.setDepth(depth);
        question.setTimestampLastModified(Instant.now().toString());
        questionEnvelope.setContent(question);
        Context.get().storeEnvelope(questionEnvelope);
        return question;
    } catch (EnvelopeNotFoundException e) {
        throw new ResourceNotFoundException("Question not found");
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not fetch question envelope", e);
    }
}
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 3 with EnvelopeNotFoundException

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

the class NoracleQuestionService method changeQuestionText.

@Override
public Question changeQuestionText(String questionId, String text) throws ServiceInvocationException {
    if (questionId == null) {
        throw new InvocationBadArgumentException("No question id given");
    }
    try {
        Envelope questionEnvelope = Context.get().requestEnvelope(getQuestionEnvelopeIdentifier(questionId));
        Question question = (Question) questionEnvelope.getContent();
        question.setText(text);
        question.setTimestampLastModified(Instant.now().toString());
        questionEnvelope.setContent(question);
        Context.get().storeEnvelope(questionEnvelope);
        return question;
    } catch (EnvelopeNotFoundException e) {
        throw new ResourceNotFoundException("Question not found");
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope Access Denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not fetch question envelope", e);
    }
}
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 4 with EnvelopeNotFoundException

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

the class NoracleQuestionService method linkQuestionToSpace.

public boolean linkQuestionToSpace(String spaceId, String questionId) {
    int questionNumber;
    for (questionNumber = 1; questionNumber < MAX_QUESTIONS_PER_SPACE; questionNumber++) {
        try {
            Context.get().requestEnvelope(buildSpaceQuestionNumberId(spaceId, questionNumber));
        } catch (EnvelopeNotFoundException e) {
            // found free question number
            break;
        } catch (Exception e) {
        // XXX logging
        }
    }
    try {
        Envelope spaceQuestionEnv = Context.get().createEnvelope(buildSpaceQuestionNumberId(spaceId, questionNumber));
        spaceQuestionEnv.setPublic();
        spaceQuestionEnv.setContent(questionId);
        Context.get().storeEnvelope(spaceQuestionEnv);
        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 5 with EnvelopeNotFoundException

use of i5.las2peer.api.persistency.EnvelopeNotFoundException 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)

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