@Override public Response createUserConversation(String intent, String userId, UserConversation userConversation) { try { userConversationStore.createUserConversation(userConversation); userConversationCache.put(calculateCacheKey(intent, userId), userConversation); return Response.ok().build(); } catch (IResourceStore.ResourceAlreadyExistsException e) { throw new WebApplicationException(e.getLocalizedMessage(), Response.Status.CONFLICT); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage()); } }
@Override public Response createBotTrigger(BotTriggerConfiguration botTriggerConfiguration) { try { botTriggerStore.createBotTrigger(botTriggerConfiguration); botTriggersCache.put(botTriggerConfiguration.getIntent(), botTriggerConfiguration); return Response.ok().build(); } catch (IResourceStore.ResourceAlreadyExistsException e) { throw new WebApplicationException(e.getLocalizedMessage(), Response.Status.CONFLICT); } catch (IResourceStore.ResourceStoreException e) { log.error(e.getLocalizedMessage(), e); throw new InternalServerErrorException(e.getLocalizedMessage()); } }
void createBotTrigger(BotTriggerConfiguration botTriggerConfiguration) throws ResourceStoreException, ResourceAlreadyExistsException { if (collection.find(new Document(INTENT_FIELD, botTriggerConfiguration.getIntent())).first() != null) { String message = "BotTriggerConfiguration with intent=%s already exists"; message = String.format(message, botTriggerConfiguration.getIntent()); throw new ResourceAlreadyExistsException(message); } collection.insertOne(createDocument(botTriggerConfiguration)); }
void createUserConversation(UserConversation userConversation) throws ResourceStoreException, ResourceAlreadyExistsException { Document filter = new Document(); filter.put(INTENT_FIELD, userConversation.getIntent()); filter.put(USER_ID_FIELD, userConversation.getUserId()); if (collection.find(filter).first() != null) { String message = "UserConversation with intent=%s does already exist"; message = String.format(message, userConversation.getIntent()); throw new ResourceAlreadyExistsException(message); } collection.insertOne(createDocument(userConversation)); }