|
24 | 24 | /** |
25 | 25 | * Noracle Agents Service |
26 | 26 | * |
27 | | - * This service is used to handle agents metadata in a distributed Noracle system. |
| 27 | + * This service is used to handle agents metadata in a distributed Noracle |
| 28 | + * system. |
28 | 29 | * |
29 | 30 | */ |
30 | 31 | public class NoracleAgentService extends Service implements INoracleAgentService { |
@@ -124,10 +125,6 @@ public SpaceSubscriptionList getSpaceSubscriptions(String agentId) throws Servic |
124 | 125 | } |
125 | 126 | } |
126 | 127 |
|
127 | | - private String buildSubscriptionId(String agentId) { |
128 | | - return "spacesubscriptions-" + agentId; |
129 | | - } |
130 | | - |
131 | 128 | @Override |
132 | 129 | public SpaceSubscription updateSpaceSubscription(String agentId, String spaceId, String[] selectedQuestions) |
133 | 130 | throws ServiceInvocationException { |
@@ -162,8 +159,58 @@ public SpaceSubscription updateSpaceSubscription(String agentId, String spaceId, |
162 | 159 |
|
163 | 160 | @Override |
164 | 161 | public NoracleAgentProfile updateAgentProfile(String agentName) throws ServiceInvocationException { |
165 | | - // TODO Implement (create or update should both be done here) |
166 | | - return null; |
| 162 | + Agent mainAgent = Context.get().getMainAgent(); |
| 163 | + String envIdentifier = buildAgentProfileId(mainAgent.getIdentifier()); |
| 164 | + Envelope env; |
| 165 | + NoracleAgentProfile profile; |
| 166 | + // look for existing profile, otherwise create one |
| 167 | + try { |
| 168 | + try { |
| 169 | + env = Context.get().requestEnvelope(envIdentifier); |
| 170 | + profile = (NoracleAgentProfile) env.getContent(); |
| 171 | + } catch (EnvelopeNotFoundException e) { |
| 172 | + env = Context.get().createEnvelope(envIdentifier); |
| 173 | + profile = new NoracleAgentProfile(); |
| 174 | + } |
| 175 | + } catch (EnvelopeAccessDeniedException e) { |
| 176 | + throw new ServiceAccessDeniedException("Envelope access denied"); |
| 177 | + } catch (EnvelopeOperationFailedException e) { |
| 178 | + throw new InternalServiceException("Could not create new envelope for noracle agent profile", e); |
| 179 | + } |
| 180 | + profile.setName(agentName); |
| 181 | + env.setContent(profile); |
| 182 | + env.setPublic(); |
| 183 | + try { |
| 184 | + Context.get().storeEnvelope(env, mainAgent); |
| 185 | + } catch (EnvelopeAccessDeniedException e) { |
| 186 | + throw new ServiceAccessDeniedException("Envelope access denied"); |
| 187 | + } catch (EnvelopeOperationFailedException e) { |
| 188 | + throw new InternalServiceException("Storing envelope with noracle agent profile failed", e); |
| 189 | + } |
| 190 | + return profile; |
| 191 | + } |
| 192 | + |
| 193 | + @Override |
| 194 | + public NoracleAgentProfile getAgentProfile(String agentId) throws ServiceInvocationException { |
| 195 | + String envIdentifier = buildAgentProfileId(agentId); |
| 196 | + try { |
| 197 | + Envelope env = Context.get().requestEnvelope(envIdentifier); |
| 198 | + return (NoracleAgentProfile) env.getContent(); |
| 199 | + } catch (EnvelopeAccessDeniedException e) { |
| 200 | + throw new ServiceAccessDeniedException("Envelope access denied"); |
| 201 | + } catch (EnvelopeOperationFailedException e) { |
| 202 | + throw new InternalServiceException("Could not fetch agent profile", e); |
| 203 | + } catch (EnvelopeNotFoundException e) { |
| 204 | + return new NoracleAgentProfile(); |
| 205 | + } |
| 206 | + } |
| 207 | + |
| 208 | + private String buildSubscriptionId(String agentId) { |
| 209 | + return "spacesubscriptions-" + agentId; |
| 210 | + } |
| 211 | + |
| 212 | + private String buildAgentProfileId(String agentId) { |
| 213 | + return "noracleagentprofile-" + agentId; |
167 | 214 | } |
168 | 215 |
|
169 | 216 | } |
0 commit comments