1919import i5 .las2peer .api .security .AgentAccessDeniedException ;
2020import i5 .las2peer .api .security .AgentAlreadyExistsException ;
2121import i5 .las2peer .api .security .AgentLockedException ;
22+ import i5 .las2peer .api .security .AgentNotFoundException ;
2223import i5 .las2peer .api .security .AgentOperationFailedException ;
2324import i5 .las2peer .api .security .AnonymousAgent ;
2425import i5 .las2peer .api .security .GroupAgent ;
2526import i5 .las2peer .security .GroupAgentImpl ;
2627import i5 .las2peer .security .UserAgentImpl ;
2728import i5 .las2peer .serialization .SerializationException ;
2829import i5 .las2peer .services .noracleService .api .INoracleSpaceService ;
30+ import i5 .las2peer .services .noracleService .model .NoracleAgentProfile ;
2931import i5 .las2peer .services .noracleService .model .Space ;
3032import i5 .las2peer .services .noracleService .model .SpaceInviteAgent ;
33+ import i5 .las2peer .services .noracleService .model .SpaceSubscribersList ;
3134import i5 .las2peer .tools .CryptoException ;
3235
3336/**
@@ -126,6 +129,31 @@ public Space getSpace(String spaceId) throws ServiceInvocationException {
126129 Space space = (Space ) env .getContent ();
127130 return space ;
128131 }
132+
133+ @ Override
134+ public SpaceSubscribersList getSubscribers (String spaceId ) throws ServiceInvocationException {
135+ if (spaceId == null || spaceId .isEmpty ()) {
136+ throw new InvocationBadArgumentException ("No space id given" );
137+ }
138+ try {
139+ UserAgentImpl inviteAgent = this .getInviteAgent (spaceId );
140+ GroupAgent memberAgent = this .getMemberAgent (spaceId );
141+ memberAgent .unlock (Context .get ().getMainAgent ());
142+ String [] memberIds = memberAgent .getMemberList ();
143+ SpaceSubscribersList subscribers = new SpaceSubscribersList ();
144+ for (int i = 0 ; i < memberIds .length ; i ++) {
145+ if (!memberIds [i ].equals (inviteAgent .getIdentifier ())) {
146+ UserAgentImpl agent = (UserAgentImpl ) Context .get ().fetchAgent (memberIds [i ]);
147+ NoracleAgentProfile profile = new NoracleAgentProfile ();
148+ profile .setName (agent .getLoginName ());
149+ subscribers .add (profile );
150+ }
151+ }
152+ return subscribers ;
153+ } catch (Exception e ) {
154+ throw new ServiceInvocationException ("Could not fetch list" , e );
155+ }
156+ }
129157
130158 public void joinSpace (String spaceId , String spaceSecret ) throws ServiceInvocationException {
131159 if (spaceId == null || spaceId .isEmpty ()) {
@@ -134,15 +162,9 @@ public void joinSpace(String spaceId, String spaceSecret) throws ServiceInvocati
134162 throw new ServiceAccessDeniedException ("No space secret given" );
135163 }
136164 try {
137- String inviteAgentEnvelopeId = getInviteMappingIdentifier (spaceId );
138- Envelope inviteAgentMapping = Context .get ().requestEnvelope (inviteAgentEnvelopeId );
139- String inviteAgentId = (String ) inviteAgentMapping .getContent ();
140- UserAgentImpl inviteAgent = (UserAgentImpl ) Context .get ().fetchAgent (inviteAgentId );
165+ UserAgentImpl inviteAgent = this .getInviteAgent (spaceId );
141166 inviteAgent .unlock (spaceSecret );
142- String memberAgentEnvelopeId = getMemberMappingIdentifier (spaceId );
143- Envelope memberAgentMapping = Context .get ().requestEnvelope (memberAgentEnvelopeId );
144- String memberAgentId = (String ) memberAgentMapping .getContent ();
145- GroupAgent memberAgent = (GroupAgent ) Context .get ().fetchAgent (memberAgentId );
167+ GroupAgent memberAgent = this .getMemberAgent (spaceId );
146168 memberAgent .unlock (inviteAgent );
147169 memberAgent .addMember (Context .get ().getMainAgent ());
148170 Context .get ().storeAgent (memberAgent );
@@ -152,6 +174,22 @@ public void joinSpace(String spaceId, String spaceSecret) throws ServiceInvocati
152174 throw new ServiceInvocationException ("Could not join space" , e );
153175 }
154176 }
177+
178+ private UserAgentImpl getInviteAgent (String spaceId ) throws AgentNotFoundException , AgentOperationFailedException , EnvelopeAccessDeniedException , EnvelopeNotFoundException , EnvelopeOperationFailedException {
179+ String inviteAgentEnvelopeId = getInviteMappingIdentifier (spaceId );
180+ Envelope inviteAgentMapping = Context .get ().requestEnvelope (inviteAgentEnvelopeId );
181+ String inviteAgentId = (String ) inviteAgentMapping .getContent ();
182+ UserAgentImpl inviteAgent = (UserAgentImpl ) Context .get ().fetchAgent (inviteAgentId );
183+ return inviteAgent ;
184+ }
185+
186+ private GroupAgent getMemberAgent (String spaceId ) throws EnvelopeAccessDeniedException , EnvelopeNotFoundException , EnvelopeOperationFailedException , AgentNotFoundException , AgentOperationFailedException {
187+ String memberAgentEnvelopeId = getMemberMappingIdentifier (spaceId );
188+ Envelope memberAgentMapping = Context .get ().requestEnvelope (memberAgentEnvelopeId );
189+ String memberAgentId = (String ) memberAgentMapping .getContent ();
190+ GroupAgent memberAgent = (GroupAgent ) Context .get ().fetchAgent (memberAgentId );
191+ return memberAgent ;
192+ }
155193
156194 private String buildSpaceId () {
157195 String result = "" ;
0 commit comments