Search in sources :

Example 16 with InternalServiceException

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

the class NoracleAgentService method updateAgentProfile.

@Override
public NoracleAgentProfile updateAgentProfile(String agentName) throws ServiceInvocationException {
    Agent mainAgent = Context.get().getMainAgent();
    String envIdentifier = buildAgentProfileId(mainAgent.getIdentifier());
    Envelope env;
    NoracleAgentProfile profile;
    // look for existing profile, otherwise create one
    try {
        try {
            env = Context.get().requestEnvelope(envIdentifier);
            profile = (NoracleAgentProfile) env.getContent();
        } catch (EnvelopeNotFoundException e) {
            env = Context.get().createEnvelope(envIdentifier);
            profile = new NoracleAgentProfile();
        }
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope access denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not create new envelope for noracle agent profile", e);
    }
    profile.setName(agentName);
    env.setContent(profile);
    env.setPublic();
    try {
        Context.get().storeEnvelope(env, mainAgent);
    } catch (EnvelopeAccessDeniedException e) {
        throw new ServiceAccessDeniedException("Envelope access denied");
    } catch (EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Storing envelope with noracle agent profile failed", e);
    }
    return profile;
}
Also used : AnonymousAgent(i5.las2peer.api.security.AnonymousAgent) Agent(i5.las2peer.api.security.Agent) NoracleAgentProfile(i5.las2peer.services.noracleService.model.NoracleAgentProfile) 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 17 with InternalServiceException

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

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

the class NoracleSpaceService method createSpace.

@Override
public Space createSpace(String name) throws ServiceInvocationException {
    Agent mainAgent = Context.get().getMainAgent();
    if (mainAgent instanceof AnonymousAgent) {
        throw new ServiceNotAuthorizedException("You have to be logged in to create a space");
    }
    String spaceId = buildSpaceId();
    String spaceSecret = generateSpaceSecret();
    SpaceInviteAgent spaceInviteAgent;
    try {
        spaceInviteAgent = new SpaceInviteAgent(spaceSecret);
        spaceInviteAgent.unlock(spaceSecret);
        Context.get().storeAgent(spaceInviteAgent);
    } catch (AgentOperationFailedException | CryptoException e) {
        throw new InternalServiceException("Could not create space invite agent", e);
    } catch (AgentAccessDeniedException | AgentAlreadyExistsException | AgentLockedException e) {
        throw new InternalServiceException("Could not store space invite agent", e);
    }
    try {
        Envelope envInviteMapping = Context.get().createEnvelope(getInviteMappingIdentifier(spaceId));
        envInviteMapping.setPublic();
        envInviteMapping.setContent(spaceInviteAgent.getIdentifier());
        Context.get().storeEnvelope(envInviteMapping);
    } catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
        throw new InternalServiceException("Could not store space invite mapping", e);
    }
    GroupAgentImpl spaceMemberGroupAgent;
    try {
        spaceMemberGroupAgent = GroupAgentImpl.createGroupAgent(new Agent[] { spaceInviteAgent, mainAgent });
        spaceMemberGroupAgent.unlock(mainAgent);
        Context.get().storeAgent(spaceMemberGroupAgent);
    } catch (AgentOperationFailedException | CryptoException | SerializationException e) {
        throw new InternalServiceException("Could not create space member group agent", e);
    } catch (AgentAccessDeniedException | AgentAlreadyExistsException | AgentLockedException e) {
        throw new InternalServiceException("Could not store space member group agent", e);
    }
    try {
        Envelope envGroupMapping = Context.get().createEnvelope(getMemberMappingIdentifier(spaceId));
        envGroupMapping.setPublic();
        envGroupMapping.setContent(spaceMemberGroupAgent.getIdentifier());
        Context.get().storeEnvelope(envGroupMapping);
    } catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
        throw new InternalServiceException("Could not store space group member mapping", e);
    }
    Envelope env;
    try {
        env = Context.get().createEnvelope(getSpaceEnvelopeIdentifier(spaceId), mainAgent);
    } catch (EnvelopeOperationFailedException | EnvelopeAccessDeniedException e) {
        throw new InternalServiceException("Could not create envelope for space", e);
    }
    env.addReader(spaceMemberGroupAgent);
    Space space = new Space(spaceId, spaceSecret, name, mainAgent.getIdentifier(), spaceMemberGroupAgent.getIdentifier());
    env.setContent(space);
    try {
        Context.get().storeEnvelope(env, mainAgent);
    } catch (EnvelopeAccessDeniedException | EnvelopeOperationFailedException e) {
        throw new InternalServiceException("Could not store space envelope", e);
    }
    return space;
}
Also used : Space(i5.las2peer.services.noracleService.model.Space) SpaceInviteAgent(i5.las2peer.services.noracleService.model.SpaceInviteAgent) SerializationException(i5.las2peer.serialization.SerializationException) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) SpaceInviteAgent(i5.las2peer.services.noracleService.model.SpaceInviteAgent) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) Envelope(i5.las2peer.api.persistency.Envelope) GroupAgentImpl(i5.las2peer.security.GroupAgentImpl) CryptoException(i5.las2peer.tools.CryptoException)

Example 19 with InternalServiceException

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

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