public int deleteMailContext(String workflowId) { try { this.db = getConnection(); this.dbCollectionMail = this.db.getCollection(this.config.getMailCollection()); JacksonDBCollection<MailContext, String> coll; coll = JacksonDBCollection.wrap(this.dbCollectionMail, MailContext.class, String.class); if (coll.getCount(DBQuery.is("_id", workflowId)) != 0) { coll.removeById(workflowId); } else { return NOT_FOUND_IN_DATABASE; } } catch (UnknownHostException ex) { Logger.getLogger(DaoMailContext.class.getName()).log(Level.SEVERE, null, ex); return ERROR_DELETING_DATA; } return DATA_SUCCESSFULLY_DELETED; }
/*================================================================= | Function storeMailContext | Propósito: Store the mail settings for a particular worlflow | Return values: ERROR / SUCCES code (int) ===================================================================*/ public int storeMailContext(MailContext mailContext) { try { this.db = getConnection(); this.dbCollectionMail = this.db.getCollection(this.config.getMailCollection()); JacksonDBCollection<MailContext, String> coll; coll = JacksonDBCollection.wrap(this.dbCollectionMail, MailContext.class, String.class); // if exist update if (coll.getCount(DBQuery.is("_id", mailContext.getAsociatedWorflow())) != 0) { coll.updateById(mailContext.getAsociatedWorflow(), mailContext); } else { coll.insert(mailContext); } } catch (UnknownHostException ex) { Logger.getLogger(DaoMailContext.class.getName()).log(Level.SEVERE, null, ex); return ERROR_STORING_DATA; } return DATA_SUCCESSFULLY_STORED; }