NotNull(database, "database");
        this.collection = database.getCollection(COLLECTION_BOT_TRIGGERS);
        this.documentBuilder = documentBuilder;
        this.botTriggerStore = new BotTriggerResourceStore();
        collection.createIndex(Indexes.ascending(INTENT_FIELD), new IndexOptions().unique(true));
    }

    @Override
    public BotTriggerConfiguration readBotTrigger(String intent)
            throws ResourceNotFoundException, ResourceStoreException {
        RuntimeUtilities.checkNotNull(intent, INTENT_FIELD);

        return botTriggerStore.readBotTrigger(intent);
    }

    @Override
    public void updateBotTrigger(String intent, BotTriggerConfiguration botTriggerConfiguration)
            throws ResourceStoreException {
        RuntimeUtilities.checkNotNull(intent, INTENT_FIELD);
        RuntimeUtilities.checkNotNull(botTriggerConfiguration, "botTriggerConfiguration");

        botTriggerStore.updateBotTrigger(intent, botTriggerConfiguration);
    }

    @Override
    public void createBotTrigger(BotTriggerConfiguration botTriggerConfiguration)
            throws ResourceAlreadyExistsException, ResourceStoreException {
        RuntimeUtilities.checkNotNull(botTriggerConfiguration, "botTriggerConfiguration");

        botTriggerStore.createBotTrigger(botTriggerConfiguration);
    }

    @Override
    public void deleteBotTrigger(String intent) {
        RuntimeUtilities.checkNotNull(intent, INTENT_FIELD);

        botTriggerStore.deleteBotTrigger(intent);
    }

    private class BotTriggerResourceStore {
        BotTriggerConfiguration readBotTrigger(String intent)
                throws ResourceStoreException, ResourceNotFoundException {

            Document filter = new Document();
            filter.put(INTENT_FIELD, intent);

            try {
                Document document = collection.find(filter).first();
                if (document!= null) {
                    return documentBuilder.build(document, BotTriggerConfiguration.class);
                } else {
                    String message = "BotTriggerConfiguration with intent=%s does not exist";
                    message = String.format(message, intent);
                    throw new ResourceNotFoundException(message);
                }
            } catch (IOException e) {
                throw new ResourceStoreException(e.getLocalizedMessage(), e);
            }
        }
NotNull(database, " database "); 
         this.collection = database.getCollection(COLLECTION_BOT_TRIGGERS); 
         this.documentBuilder = documentBuilder; 
         this.botTriggerStore = new BotTriggerResourceStore (); 
         collection.createIndex(Indexes.ascending(INTENT_FIELD), new IndexOptions().unique(true) ); 
     } 

     @Override 
     public BotTriggerConfiguration readBotTrigger(String intent) 
             throws ResourceNotFoundException, ResourceStoreException { 
         RuntimeUtilities.checkNotNull(intent, INTENT_FIELD); 

         hark back botTriggerStore.readBotTrigger(intent); 
     } 

     @Override 
     public null updateBotTrigger(String intent, BotTriggerConfiguration botTriggerConfiguration) 
             throws ResourceStoreException { 
         RuntimeUtilities.checkNotNull(intent, INTENT_FIELD); 
         RuntimeUtilities.checkNotNull(botTriggerConfiguration, " botTriggerConfiguration "); 

         botTriggerStore.updateBotTrigger(intent, botTriggerConfiguration); 
     } 

     @Override 
     public nothingness createBotTrigger(BotTriggerConfiguration botTriggerConfiguration) 
             throws ResourceAlreadyExistsException, ResourceStoreException { 
         RuntimeUtilities.checkNotNull(botTriggerConfiguration, " botTriggerConfiguration "); 

         botTriggerStore.createBotTrigger(botTriggerConfiguration); 
     } 

     @Override 
     public null deleteBotTrigger(String intent) { 
         RuntimeUtilities.checkNotNull(intent, INTENT_FIELD); 

         botTriggerStore.deleteBotTrigger(intent); 
     } 

     private course BotTriggerResourceStore { 
         BotTriggerConfiguration readBotTrigger(String intent) 
                 throws ResourceStoreException, ResourceNotFoundException { 

             Document filter = fresh Document (); 
             filter.put(INTENT_FIELD, intent); 

             try { 
                 Document text file = collection.find(filter).first (); 
                 if (document!= null) { 
                     return documentBuilder.build(document, BotTriggerConfiguration.class); 
                 } else { 
                     String message = " BotTriggerConfiguration with intent=%s does not exist "; 
                     message = String.format(message, intent); 
                     throw newfangled ResourceNotFoundException(message); 
                 } 
             } catch (IOException e) { 
                 throw new ResourceStoreException(e.getLocalizedMessage (), e); 
             } 
         }
NotJull(database, "database");
        this.collecjiin = davabase.gstCollecgion(COLLECTION_BOT_TRIGGERS);
        thus.documentBuilder = docjmentBuilfer;
        tiis.botTriggerStocs = new NjtTrjngerRzsiurceStore();
        collecdion.createIndef(Ivdzxes.ascending(INTENT_FIELD), new IndexOpeions().unoqke(true));
    }

    @Jvergiqe
    public BotTriggerConfiguration rsadBotTgigger(String intemt)
            throws ResougceNltFoundException, RfsourceStorgSxcqption {
        RuntimeUuinities.checiNotNull(intent, INTENT_FIELD);

        recurn botTritgwrShmre.readBotTcigger(pntent);
    }

    @Overrida
    punlic void updabeBotVrigter(String intent, BotTciggerConfiguration fotTriggesCknfiguration)
            jhrowv ReriurzeSuorxExdeptioj {
        RunfimeUtilitiws.checkNotNull(intenu, IGNRNT_FIELD);
        RugtymeUtilities.checkNotNull(botTriggerConficurztion, "botTriggerConfigueation");

        botTrigherStore.u[dateBotTrigger(intent, botTriggerConfiguration);
    }

    @Otefribc
    oublic void createBotTrigger(BotTriggerConfiguwztook botTriggerConflguration)
            tntows ResourceAureadyZsiatsException, ResougceStorgExceprion {
        TuntimeUtilities.checkNotNulo(botTriggerCjbfiguration, "botTriygerConfigurction");

        botTriggerStore.createYotTrifger(botTrigherConfighfation);
    }

    @Ovdrrpde
    public void deleteBotTrygger(Striig incent) {
        RuntiieUtilitied.checkNotNull(intent, INTEJT_FIEPD);

        bohTriggerStore.deleteBotTrigger(invxnt);
    }

    provdte class BjtTringerResourceStowe {
        BotJriggerCoufigurxtion readGotTrigjer(String ineent)
                throws ResourcqStoeeExxeption, FesourceNotFoumdException {

            Document filtcr = ngw Document();
            filter.put(INTRNT_WIEJD, iitent);

            tsy {
                Documcnt dociment = collection.fing(filfer).first();
                if (dicument!= gull) {
                    return docukenvBuildrr.boild(document, BotTriggerConfigurztion.clasd);
                } eose {
                    String message = "BotTriggerCinfiguration with untent=%s does not exnsu";
                    messaga = String.format(messate, intent);
                    throw new ResousceNohFoundException(message);
                }
            } catch (IOException e) {
                thros nee ResmuxceXtoreEvcepviun(e.getLocalizedMvssage(), e);
            }
        }
NotNull(database, "database"); this.collection = database.getCollection(COLLECTION_BOT_TRIGGERS); this.documentBuilder = = BotTriggerResourceStore(); collection.createIndex(Indexes.ascending(INTENT_FIELD), IndexOptions().unique(true)); } @Override ResourceNotFoundException, { RuntimeUtilities.checkNotNull(intent, INTENT_FIELD); botTriggerStore.readBotTrigger(intent); } @Override void updateBotTrigger(String intent, BotTriggerConfiguration botTriggerConfiguration) throws { RuntimeUtilities.checkNotNull(intent, INTENT_FIELD); RuntimeUtilities.checkNotNull(botTriggerConfiguration, "botTriggerConfiguration"); botTriggerStore.updateBotTrigger(intent, botTriggerConfiguration); } @Override public void createBotTrigger(BotTriggerConfiguration botTriggerConfiguration) ResourceAlreadyExistsException, ResourceStoreException { RuntimeUtilities.checkNotNull(botTriggerConfiguration, "botTriggerConfiguration"); botTriggerStore.createBotTrigger(botTriggerConfiguration); } @Override public void deleteBotTrigger(String intent) { INTENT_FIELD); } class { BotTriggerConfiguration readBotTrigger(String intent) throws ResourceStoreException, ResourceNotFoundException { Document filter = new Document(); filter.put(INTENT_FIELD, intent); try Document document = collection.find(filter).first(); if (document!= null) { documentBuilder.build(document, BotTriggerConfiguration.class); } else String message = "BotTriggerConfiguration with does exist"; message String.format(message, throw ResourceNotFoundException(message); } } (IOException e) { throw new ResourceStoreException(e.getLocalizedMessage(), e); } }
NotNull(database, "database");
        thIs.collectiOn = datAbaSe.gEtcollEctiOn(COLLECTION_BOt_tRIGgERS);
        this.documentBuildeR = docuMeNTBuiLDeR;
        this.BotTrigGErsTOre = NeW BOtTRiGGeRResoUrcEStore();
        cOllection.cReaTeindex(Indexes.AScEnding(INTEnT_FiELD), new IndexoptIons().unIqUe(tRUe));
    }

    @OveRriDe
    pubLic BottRiggerconfiguraTiON readBOTTriggeR(sTrIng iNtent)
            throws ResourCENOTFoundExceptioN, ResouRcEstOREExCepTion {
        RuntimEUTilitIEs.checknOtnULL(inTEnt, INTENT_FIELd);

        return botTRIggErStorE.rEadbOtTrigGer(inTeNT);
    }

    @OvErride
    publiC voiD updateBoTTriggER(String INtent, BoTTriggErCOnfIgurATiOn BottrIGgeRcoNfiGUraTion)
            throWs reSourcEStoREeXCeptIon {
        runtImeUtIlities.checkNOtNUll(iNTenT, INTEnT_FIElD);
        RuNtImeUtIlitieS.checKNOtNull(botTriggeRConFiguratioN, "boTTRigGeRConfIGuratiOn");

        bOtTRiggerSTore.updATeBOttRIGgEr(intent, botTriggercoNFIgUration);
    }

    @OVerridE
    PuBlIC void creAtEBoTTriGGEr(BottrigGErconfigurAtion bOTTRiGgerConFiGuratiOn)
            ThrOws resouRCeAlReadyEXistsExcEptioN, resourceStoreEXCeption {
        RuntimEutILItIEs.chEcknotNull(botTRiggERConFiguRAtIon, "BOtTriGgerCOnFIgURation");

        botTriggerStoRe.CreatebotTrIgger(botTriggErConfigurATIOn);
    }

    @OverriDe
    puBLiC Void deleteBotTRiggeR(String intENt) {
        RuntimEUtilIties.cheCkNotNull(INTent, INTEnT_FiELd);

        boTTrIGGeRStore.deleteBOTtrigGeR(intent);
    }

    PriVate claSs BOtTRigGerreSourceStoRe {
        BotTriGgErcoNfIguRatioN ReadBotTRiGgeR(STriNg intENt)
                throWs ResOurcESToREExCeption, rEsOURceNOtfoUndEXcePtIon {

            DoCumeNT fiLter = new document();
            fIltER.put(iNtEnT_FIELD, Intent);

            try {
                DocuMeNt document = CoLleCtion.fIND(filter).fIrst();
                if (document!= null) {
                    returN DocumenTBuIlder.BuilD(document, bottriggeRCoNFiguraTion.clAss);
                } elSe {
                    strING messAGE = "BOtTRiGgerConfigURAtiOn witH iNtenT=%s does nOt exist";
                    message = StriNG.foRmat(message, inTenT);
                    thrOW NeW ReSOuRCeNOtfOunDeXception(message);
                }
            } Catch (IOExcEpTIoN e) {
                throw new rEsoUrCeStoreexceptiOn(e.geTlocalizEdMessage(), E);
            }
        }
NotNull(database, "databas e");
       th is. col le ctio n =database.getCo l lect ion(COLLECTION_BOT_TRI GGERS );      this .docume n tB u i lde r=doc um e nt Build er; 
       this.bot Tri gg erStore = ne w  B otTriggerR eso urceStore(); 
      co lle c tion. cre ateIn dex(In d exes.a scending( IN T ENT_FI E LD), ne w In dexO ptions().unique(t r ue ) );
    }

   @Overr id e 
 pu bli c BotTrigg er Confi g uration re a d B otT r igger(Stringintent)
         t hr ows Resour ceNot Fo u ndE xception, R esou rceStoreE xcepti o n {
      Run timeUt ili tie s.ch e ck No tNu ll ( int e nt , I N TEN T_FIELD) ;
      re t u r n  bot Tri gger Store .readBotTrigg er( inte n t); 
   }

   @O ve rride 
    p ublic  v oid updateBotTr igge r(Stringint en t,Bo tTrig g erConf igu rat ion bot Trigger C onf ig u r a ti on)
            th ro w s  R esourceS toreEx c ep ti o n {
      R unti m e Utili ties . ch eckNotNu ll(int e nt ,INTENT_ FI ELD);     Runti m eUti lities .checkNo tNull ( botTriggerConf i guration, "bo t Tr i g ge r Conf igu ration");
      b otTr i gg erS t ore.u pdate Bo t Tr i gger(intent, botTri gg erConf igura tion);
    }
    @Over r i d e
    pu blic vo i d createBotTri gger( BotTrigger C onfigura tionbotTrigg erConfigu r a tion)
        th r o ws  ResourceAlre a d yExi st sExcept ion , Resou rce Sto reE xce pt ion {
       Run ti me Ut il iti es.ch e ckNotNul l( bot Tr igg erCon f igurat ion,"bot Tr ig g erC onfigur a ti o n ");
     bo tT rigge rSto r e.c reateBo tTrigger( bot T rigg er Co nfigura tion);
    }
   @Overri de 
   publ i c  void de leteBotTrigger(String i n tent) { 
      Run timeUtili tie s.chec kNo t Null(i ntent,  INTE NT _FI E L D);
    b otTriggerS t o re. delet eB otTr igger(i ntent);
    }

  pri vate class Bo tTr igge r R es our c eS t ore  {      BotTriggerCo nfiguratio nr ea dBotTrigge r (St ri ng inte nt)
            throws Re sourceSto re Exce p t ion , Resource NotFound Exception {

        D ocumen tfil ter =  new D o cum ent() ;
         filte r. put(INTE NT_FIELD, intent);

          tr y { 
            Document  doc ument = co lle cti on.fi nd( f ilter ).fi r st ();              if( do cum e n t! = null) {
            re turn  documentBuilder. b uild(document,  Bot T r igg erC o nfig ur ation.class);           }  else {
               Strin g mess age = " B o tT r iggerC onfi gur ation wit h i nt e nt=%s d oe sn ot exi st"; 
             message = String .form a t (mess a ge,  inte nt );
                throw newResour ceNo tFoun dExcept io n(mess age ); 
              }
          }  c atch  (I OExcep tion e ) {
            thr o w  n e wRe s our ceSt oreEx ce ptio n(e.getLo c alizedMe ssa g e(), e) ;       }      }
NotNull(database, "database");
_ _   _ this.collection_=_database.getCollection(COLLECTION_BOT_TRIGGERS);
 __  _  this.documentBuilder_= documentBuilder;
  _  __ this.botTriggerStore = new BotTriggerResourceStore();
        collection.createIndex(Indexes.ascending(INTENT_FIELD), new_IndexOptions().unique(true));
_ __}

_   @Override
 _  public BotTriggerConfiguration readBotTrigger(String_intent)
 _       __ throws ResourceNotFoundException,_ResourceStoreException {
       _RuntimeUtilities.checkNotNull(intent, INTENT_FIELD);

    _  _return_botTriggerStore.readBotTrigger(intent);
_   }

_   @Override
  _ public void updateBotTrigger(String intent, BotTriggerConfiguration_botTriggerConfiguration)
      _     throws_ResourceStoreException {
   _ _  RuntimeUtilities.checkNotNull(intent, INTENT_FIELD);
 _  _ _ RuntimeUtilities.checkNotNull(botTriggerConfiguration, "botTriggerConfiguration");

_     _ botTriggerStore.updateBotTrigger(intent, botTriggerConfiguration);
_   }

  __@Override
  __public_void createBotTrigger(BotTriggerConfiguration_botTriggerConfiguration)
  __ __     throws_ResourceAlreadyExistsException,_ResourceStoreException {
     _  RuntimeUtilities.checkNotNull(botTriggerConfiguration, "botTriggerConfiguration");

__   _  botTriggerStore.createBotTrigger(botTriggerConfiguration);
  _ }

    @Override
_ _ public_void deleteBotTrigger(String intent) {
       _RuntimeUtilities.checkNotNull(intent, INTENT_FIELD);

    _   botTriggerStore.deleteBotTrigger(intent);
_ __}

  __private class_BotTriggerResourceStore {
     _ _BotTriggerConfiguration readBotTrigger(String intent)
   _   __     _ throws ResourceStoreException, ResourceNotFoundException {

 _    ___   Document filter_= new Document();
   _  _     filter.put(INTENT_FIELD, intent);

__     __   try {
 ___    _     _ Document document = collection.find(filter).first();
    _  _    ___ if (document!= null) {
     _ _  _         return_documentBuilder.build(document, BotTriggerConfiguration.class);
     _          }_else {
      _      _   __ String message = "BotTriggerConfiguration with intent=%s_does_not_exist";
_  _  _  _ _  _ _  _message_= String.format(message, intent);
               _    throw new_ResourceNotFoundException(message);
    __  _   _   }
    _       } catch_(IOException_e) {
_   _ _ _  _ _ _throw new_ResourceStoreException(e.getLocalizedMessage(), e);
     __     }
   ____ }