Search in sources :

Example 1 with NoracleAgentProfile

use of i5.las2peer.services.noracleService.model.NoracleAgentProfile in project Distributed-Noracle-Backend by Distributed-Noracle.

the class NoracleSpaceService method getSubscribers.

@Override
public SpaceSubscribersList getSubscribers(String spaceId) throws ServiceInvocationException {
    if (spaceId == null || spaceId.isEmpty()) {
        throw new InvocationBadArgumentException("No space id given");
    }
    try {
        UserAgentImpl inviteAgent = this.getInviteAgent(spaceId);
        GroupAgent memberAgent = this.getMemberAgent(spaceId);
        memberAgent.unlock(Context.get().getMainAgent());
        String[] memberIds = memberAgent.getMemberList();
        SpaceSubscribersList subscribers = new SpaceSubscribersList();
        for (int i = 0; i < memberIds.length; i++) {
            if (!memberIds[i].equals(inviteAgent.getIdentifier())) {
                UserAgentImpl agent = (UserAgentImpl) Context.get().fetchAgent(memberIds[i]);
                NoracleAgentProfile profile = new NoracleAgentProfile();
                profile.setName(agent.getLoginName());
                subscribers.add(profile);
            }
        }
        return subscribers;
    } catch (Exception e) {
        throw new ServiceInvocationException("Could not fetch list", e);
    }
}
Also used : NoracleAgentProfile(i5.las2peer.services.noracleService.model.NoracleAgentProfile) UserAgentImpl(i5.las2peer.security.UserAgentImpl) SpaceSubscribersList(i5.las2peer.services.noracleService.model.SpaceSubscribersList) EnvelopeAccessDeniedException(i5.las2peer.api.persistency.EnvelopeAccessDeniedException) CryptoException(i5.las2peer.tools.CryptoException) EnvelopeOperationFailedException(i5.las2peer.api.persistency.EnvelopeOperationFailedException) SerializationException(i5.las2peer.serialization.SerializationException) EnvelopeNotFoundException(i5.las2peer.api.persistency.EnvelopeNotFoundException)

Example 2 with NoracleAgentProfile

use of i5.las2peer.services.noracleService.model.NoracleAgentProfile 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)

Aggregations

EnvelopeAccessDeniedException (i5.las2peer.api.persistency.EnvelopeAccessDeniedException)2 EnvelopeNotFoundException (i5.las2peer.api.persistency.EnvelopeNotFoundException)2 EnvelopeOperationFailedException (i5.las2peer.api.persistency.EnvelopeOperationFailedException)2 NoracleAgentProfile (i5.las2peer.services.noracleService.model.NoracleAgentProfile)2 Envelope (i5.las2peer.api.persistency.Envelope)1 Agent (i5.las2peer.api.security.Agent)1 AnonymousAgent (i5.las2peer.api.security.AnonymousAgent)1 UserAgentImpl (i5.las2peer.security.UserAgentImpl)1 SerializationException (i5.las2peer.serialization.SerializationException)1 SpaceSubscribersList (i5.las2peer.services.noracleService.model.SpaceSubscribersList)1 CryptoException (i5.las2peer.tools.CryptoException)1