Package com.centraview.common

Examples of com.centraview.common.CVDal


   */
  public int editFolder(int individualID, MailFolderVO folderVO)
  {
    int rowsAffected = -1;

    CVDal cvdal = new CVDal(this.dataSource);

    try {
      rowsAffected = this.editFolder(individualID, folderVO, cvdal);
    }catch(Exception e){
      System.out.println("[Exception][MailEJB] Exception thrown in editFolder(int,MailFolderVO): " + e);
      e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return rowsAffected;
  }
View Full Code Here


   * @return ArrayList of DDNameValue which will hold the account ID and Account email address.
   */
  public Vector getAccountList()
  {
    Vector accountList = new Vector();
    CVDal cvdal = new CVDal(this.dataSource);
    try {
      String selectQuery = "SELECT accountID,Address from emailaccount";
      cvdal.setSqlQuery(selectQuery);
      Collection results = cvdal.executeQuery();

      if (results != null) {
        Iterator iter = results.iterator();
        while (iter.hasNext()) {
          HashMap resultRow = (HashMap)iter.next();
          Number accountID = (Number)resultRow.get("accountID");
          String emailAddress = (String)resultRow.get("Address");
          accountList.add(new DDNameValue(accountID.intValue(),emailAddress));
        }
      }// end if (results != null)
    }catch(Exception e){
      System.out.println("[Exception][MailEJB] Exception thrown in getAccountList(): " + e.toString());
      // e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return(accountList);
  }   // end getAccountList() method
View Full Code Here

    ArrayList folders = new ArrayList();
    int defaultAccount = this.getDefaultAccountID(individualId);
    if (defaultAccount > 0) {
      MailAccountVO account = this.getMailAccountVO(defaultAccount);
      if (account.getAccountID() > 0) {
        CVDal cvdl = new CVDal(this.dataSource);
        try {
          String query = "SELECT FolderID FROM emailfolder WHERE AccountID=? AND ftype='system' AND (name='trash' OR name='inbox' OR name='drafts') ORDER BY folderId, parent";
          cvdl.setSqlQuery(query);
          cvdl.setInt(1,account.getAccountID());
          Collection results = cvdl.executeQuery();
          if (null != results) {
            Iterator iter = results.iterator();
            while(iter.hasNext()) {
              HashMap folderResult = (HashMap)iter.next();
              Number folderId = (Number)folderResult.get("FolderID");
              folders.add(this.getEmailFolder(folderId.intValue()));
            }
          } // end if (null != results)
        } finally {
          cvdl.destroy();
          cvdl = null;
        }
      } // end if (account.getAccountID() > 0)
    } // end if (defaultAccount > 0)
    return folders;
View Full Code Here

   * @return boolean - true for success, false for failure.
   */
  public boolean enableRule(int individualID, int ruleID, boolean status)
  {
    boolean returnValue = false;
    CVDal cvdal = new CVDal(this.dataSource);
    try {
      returnValue = this.enableRule(individualID, ruleID, status, cvdal);
    }catch(Exception e){
      System.out.println("[Exception][MailEJB] enableRule(int,int): " + e);
      // e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return(returnValue);
  }   // end enableRule(int,int) method
View Full Code Here

    boolean messageSent = false;
    if (mailMessageVO == null) {
      throw new SendFailedException("<error>Message cannot be null. Please set up the message.</error>");
    }// end if (mailMessageVO == null)

    CVDal cvdal = new CVDal(this.dataSource);
    try{

      String smtpServer = null;
      String username = null;
      String password = null;
      int smtpPort = 25;
      boolean connectToPopFirst = false;
      boolean smtpAuthenticationRequired = false;
      String serverType = null;
      String serverAddress = null;
      String adminEmailAddress = "";

      String query = "SELECT smtpserver, username, password, authentication, smtpport FROM emailsettings";
      cvdal.setSqlQuery(query);
      Collection results = cvdal.executeQuery();
      if (results != null) {
        Iterator iter = results.iterator();
        if (iter.hasNext()) {
          HashMap folderInfo = (HashMap)iter.next();
          smtpPort = ((Number)folderInfo.get("smtpport")).intValue();
          smtpServer = (String)folderInfo.get("smtpserver");
          username = (String)folderInfo.get("username");
          password = (String)folderInfo.get("password");
          String authentication = (String)folderInfo.get("authentication");
          if (authentication != null && authentication.equals("YES")){
            smtpAuthenticationRequired = true;
          }
          adminEmailAddress = (String)folderInfo.get("adminemailaddress");
        }
      }

      Address arrayBcc[] = new Address[0];
      Address arrayCc[] = new Address[0];
      Address arrayTo[] = new Address[0];

      //Build the JavaMail message
      Properties props = System.getProperties();
      if (smtpServer != null) {
        props.put("mail.smtp.host", smtpServer);
      }else{
        throw new SendFailedException("<error>The SMTP Server has not been setup.</error>");
      }

      Session session = Session.getDefaultInstance(props, null);
      MimeMessage message = new MimeMessage(session);

      Collection bccList = mailMessageVO.getBccList();
      Collection ccList = mailMessageVO.getCcList();
      Collection toList = mailMessageVO.getToList();
      Collection attachments = mailMessageVO.getAttachedFiles();

      String subject = mailMessageVO.getSubject();
      String body = mailMessageVO.getBody();
      String fromAddress = mailMessageVO.getFromAddress();
      String replyToAddress = mailMessageVO.getReplyTo();
      String headers = mailMessageVO.getHeaders();
      String messageType = mailMessageVO.getContentType();

      //if you don't specify the from email address we will enter the administrator email address
      if(fromAddress == null){
        fromAddress =  adminEmailAddress;
      }
      message.setFrom(new InternetAddress(fromAddress));

      if (replyToAddress != null && !replyToAddress.equals("")){
        message.setReplyTo(new Address[] {new InternetAddress(replyToAddress)});
      }

      //Add raw headers to message object
      StringTokenizer tokenizer = new StringTokenizer(headers, System.getProperty("line.separator", "\n"));
      while (tokenizer.hasMoreTokens()) {
        message.addHeaderLine(tokenizer.nextToken());
      }

      //Most email clients add this line with the name of
      //their software and the version
      message.addHeader("X-Mailer", "Centraview v. " + CentraViewConfiguration.getVersion());

      message.setSubject(subject);
      BodyPart messageBodyPart = new MimeBodyPart();
      messageBodyPart.setContent(body, messageType);

      Multipart multipart = new MimeMultipart();
      multipart.addBodyPart(messageBodyPart);

      // Handle attachments
      if (attachments != null) {
        message.setContent(multipart);
        Iterator attachmentIterator = attachments.iterator();
        while (attachmentIterator.hasNext()) {
          messageBodyPart = new MimeBodyPart();
          CvFileVO thisAttachment = (CvFileVO) attachmentIterator.next();
          String path = thisAttachment.getPhysicalFolderVO().getFullPath(null, true) + thisAttachment.getName();
          DataSource source = new FileDataSource(path);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(thisAttachment.getTitle());
          multipart.addBodyPart(messageBodyPart);
        }
      }

      message.setSentDate(new Date());

      String mailSendList = "";
      String mailFailedList = "";

      //End of Build The JavaMail message

      // We must have to send seperate message to individual.
      // We must have to keep track of message sent to list and failed while send message to particular individual.
      if (toList != null) {
        Iterator toIterator = toList.iterator();
        int count = 0;
        while (toIterator.hasNext()) {
          String toAddress = (String) toIterator.next();
          message.setRecipients(Message.RecipientType.TO, toAddress);
          try{
            messageSent = this.sendSimpleMessage(message, smtpServer, username, password, smtpPort, connectToPopFirst, smtpAuthenticationRequired, serverType, serverAddress);
          } catch(SendFailedException sfe) {
            // we will catch the invalid Address and by this way we will know that recipient will not receive the mail and we add individual in the failing list.
            Address[] invalidAddress = sfe.getInvalidAddresses();
            if (invalidAddress != null){
              mailFailedList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ toAddress + "<br>";
              messageSent = false;
            } else {
              throw new SendFailedException(sfe.getMessage());
            }
          }

          if (messageSent){
            // if the message is sent successfully to individual then add to the send list
            mailSendList += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+ toAddress + "<br>";
          }
        }
      }

      // If suppose the mailFailedList is not blank. then we have to throw error stating the succesfully send list and failed list
      if ((mailFailedList != null && !mailFailedList.equals(""))){
        //Format the message for failed user and successfully sent individual's
        // TODO: remove this HTML from the EJB layer!!!!!!! *sigh*
        String errorMessage = "<failed> <font color=\"#008000\"> Successfully Sent to : <br>"+mailSendList
                                +"</font>"
                                +"<font color=\"#FF0000\"><br> Failed : <br>"+mailFailedList
                                +"</failed></font>";
        throw new SendFailedException(errorMessage);
      }
    } finally {
      cvdal.destroy();
    }
    return messageSent;
  }// end of boolean simpleMessage(int individualID, Message message)
View Full Code Here

   * accounts, and calls this.getMail() for each account.
   * @return void
   */
  public void checkAllSupportAccounts()
  {
    CVDal cvdal = new CVDal(this.dataSource);

    try {
      cvdal.setSqlQuery("SELECT EmailAccountID AS accountID FROM supportemailaccount");
      Collection results = cvdal.executeQuery();
      cvdal.clearParameters();
      cvdal.setSqlQueryToNull();
      if (results != null && results.size() > 0) {
        Iterator iter = results.iterator();
        while (iter.hasNext()) {
          HashMap row = (HashMap)iter.next();
          Number accountID = (Number)row.get("accountID");
          this.getMail(this.getMailAccountVO(accountID.intValue()), 0);
        }
      }
    }catch(Exception e){
      System.out.println("[Exception] MailEJB.getEmailFolder: " + e.toString());
      e.printStackTrace();
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
  }
View Full Code Here

   * @return ArrayList of HashMaps representing Templates.
   */
  public ArrayList getTemplateList(int individualID, int accountID)
  {
    ArrayList templateList = new ArrayList();
    CVDal cvdal = new CVDal(this.dataSource);
    try {
      String sql = "SELECT em.messageID, em.subject FROM emailmessage em " +
                   "LEFT JOIN emailmessagefolder emf ON (em.messageID=emf.messageID) " +
                   "LEFT JOIN emailfolder ef ON (emf.folderID=ef.folderID) " +
                   "WHERE em.accountID=? AND ef.Ftype='SYSTEM' AND ef.Name=?";

      cvdal.setSqlQuery(sql);
      cvdal.setInt(1, accountID);
      cvdal.setString(2, MailFolderVO.TEMPLATES_FOLDER_NAME);
      Collection results = cvdal.executeQuery();

      if (results != null && results.size() > 0) {
        Iterator iter = results.iterator();
        while (iter.hasNext()) {
          HashMap row = (HashMap)iter.next();
          templateList.add(row);
        }
      }
    }finally{
      cvdal.destroy();
      cvdal = null;
    }
    return templateList;
  }   // end getTemplateList(int,int) method
View Full Code Here

    // rows based on record rights.  If it is true than the rights are used.
    boolean permissionSwitch = individualID < 1 ? false : true;
    boolean applyFilter = false;
    String filter = parameters.getFilter();

    CVDal cvdl = new CVDal(this.dataSource);
    try {
      if (filter != null && filter.length() > 0) {
        String str = "CREATE TABLE emaillistfilter " + filter;
        cvdl.setSqlQuery(str);
        cvdl.executeUpdate();
        cvdl.setSqlQueryToNull();
        applyFilter = true;
      }
      // We can't use the numberOfRecords in calculation we will get total message count
      // independent of the folder..
      int numberOfRecords = 0;
      if (applyFilter) {
        numberOfRecords = EJBUtil.buildListFilterTable(cvdl, "emaillistfilter", individualID, 2, "emailmessage", "MessageID", "Owner", null, permissionSwitch);
      } else if (permissionSwitch) {
        numberOfRecords = EJBUtil.buildListFilterTable(cvdl, null, individualID, 2, "emailmessage", "MessageID", "Owner", null, permissionSwitch);
      }

      // Create a temporary table with out applying the Limit on the search.
      String query = this.buildEmailListQuery(applyFilter, permissionSwitch, parameters);
      cvdl.setSqlQuery("CREATE TEMPORARY TABLE emaillist "+query);
      cvdl.executeUpdate();
      cvdl.setSqlQueryToNull();

      //get the limit criteria, concat the string with final query.
      String limit = parameters.getLimitParam();

      // Now, Finally, we can just select the email list and populate value List
      cvdl.setSqlQuery("SELECT * FROM emaillist " + limit);
      list = cvdl.executeQueryList(1);
      cvdl.setSqlQueryToNull();

      //We know that emailList table is having the total message.
      //make a count on table and assign to parameter.
      cvdl.setSqlQuery("SELECT count(MessageID) AS numberOfRecords FROM emaillist");
      Collection results = cvdl.executeQuery();
      cvdl.clearParameters();
      cvdl.setSqlQueryToNull();
      numberOfRecords = 0;
      if (results != null && results.size() > 0) {
        Iterator iter = results.iterator();
        while (iter.hasNext()) {
          HashMap row = (HashMap)iter.next();
          numberOfRecords = ((Number) row.get("numberOfRecords")).intValue();
        }
      }

      // Assign the numberOfRecords to the paramters
      parameters.setTotalRecords(numberOfRecords);

      // drop emaillist table
      cvdl.setSqlQuery("DROP TABLE emaillist");
      cvdl.executeUpdate();
      // throw away the temp filter table, if necessary.
      if (applyFilter) {
        cvdl.setSqlQueryToNull();
        cvdl.setSqlQuery("DROP TABLE emaillistfilter");
        cvdl.executeUpdate();
      }
      if (applyFilter || permissionSwitch) {
        cvdl.setSqlQueryToNull();
        cvdl.setSqlQuery("DROP TABLE listfilter");
        cvdl.executeUpdate();
      }
    }
    finally{
      cvdl.destroy();
      cvdl = null;
    }
    return new ValueListVO(list, parameters);
  }
View Full Code Here

    int accountID = parameters.getAccountID();

    boolean applyFilter = false;

    CVDal cvdl = new CVDal(this.dataSource);
    try {
      StringBuffer whereClause = new StringBuffer();
      StringBuffer fromClause = new StringBuffer();

     String orderBy = " ORDER BY " + String.valueOf(parameters.getSortColumn() + " " + parameters.getSortDirection());
    String limit = parameters.getLimitParam();

    //Since Rule Doesn't have ModuleID
    //apply the filter value on each column of emailrule table.
      if (filter != null && filter.length() > 0) {
           String queryFilter = "CREATE TEMPORARY TABLE rulelistfilter SELECT ruleID from emailrule " +
             " WHERE ruleID LIKE '%"+filter+"%' OR "+
         " accountID LIKE '%"+filter+"%' OR name LIKE '%"+filter+"%' OR "+
         " description LIKE '%"+filter+"%' OR enabled LIKE '%"+filter+"%'";
           cvdl.setSqlQuery(queryFilter);
           cvdl.executeUpdate();
           cvdl.setSqlQueryToNull();

           applyFilter = true;
           whereClause.append(" AND emailrule.ruleID = rlf.ruleID ");
           fromClause.append(" , rulelistfilter rlf ");
      }

      StringBuffer query = new StringBuffer();
      query.append("SELECT emailrule.ruleID, emailrule.name , ");
      query.append(" emailrule.description, emailrule.enabled ");
      query.append(" FROM emailrule " + fromClause.toString() + " WHERE emailrule.accountID="+accountID+" ");
      query.append(whereClause.toString());
      query.append(orderBy);

      cvdl.setSqlQuery("CREATE TEMPORARY TABLE rulelist "+query.toString());
      cvdl.executeUpdate();
      cvdl.setSqlQueryToNull();

      // Now, Finally, we can just select the rule list and populate value List
      cvdl.setSqlQuery("SELECT * FROM rulelist "+limit);
      list = cvdl.executeQueryList(1);
      cvdl.setSqlQueryToNull();

      //We know that ruleList table is having all rule associate to account .
      //make a count on table and assign to parameter.
      cvdl.setSqlQuery("SELECT count(ruleID) AS numberOfRecords FROM rulelist ");
      Collection results = cvdl.executeQuery();
      cvdl.clearParameters();
      cvdl.setSqlQueryToNull();
      int numberOfRecords = 0;
      if (results != null && results.size() > 0) {
        Iterator iter = results.iterator();
        while (iter.hasNext()) {
          HashMap row = (HashMap)iter.next();
          numberOfRecords = ((Number) row.get("numberOfRecords")).intValue();
        }
      }
      parameters.setTotalRecords(numberOfRecords);
      // drop rulelist table
      cvdl.setSqlQuery("DROP TABLE rulelist");
      cvdl.executeUpdate();
      // throw away the temp filter table, if necessary.
      if (applyFilter) {
        cvdl.setSqlQueryToNull();
        cvdl.setSqlQuery("DROP TABLE rulelistfilter");
        cvdl.executeUpdate();
      }
    } finally {
      cvdl.destroy();
      cvdl = null;
    }
    return new ValueListVO(list, parameters);
  }
View Full Code Here

   * @param folderID
   * @param accountVO
   */
  private void checkIMAPFolder(int folderID, MailAccountVO accountVO)
  {
    CVDal cvdal = new CVDal(this.dataSource);
    IMAPStore store = null;
    IMAPFolder folder = null;
    try {
      Session session = null;
      store = this.setupIMAPConnection(accountVO, session);
      MailFolderVO folderVO = this.getEmailFolder(folderID, cvdal);

      String name = folderVO.getFolderFullName();
      if (name == null) {
        name = folderVO.getFolderName();
      }
      folder = (IMAPFolder)store.getFolder(name);

      int type = folder.getType();
      if ((type & IMAPFolder.HOLDS_MESSAGES) != 0) {
        folder.open(Folder.READ_WRITE);
        Message msgs[] = folder.getMessages();
        FetchProfile fp = new FetchProfile();
        fp.add(IMAPFolder.FetchProfileItem.FLAGS);
        fp.add(UIDFolder.FetchProfileItem.UID);
        folder.fetch(msgs, fp);
        this.handleIMAPMessageArray(msgs, folder, folderID, accountVO, store, cvdal);
      }
    } catch (Exception e) {
      logger.error("[checkIMAPFolder] Exception thrown.", e);
    } finally {
      try {
        if (folder.isOpen()) {
          folder.close(false);
        }
      } catch (Exception e) {}
      try { store.close(); } catch(MessagingException e) {}
      cvdal.destroy();
    }
  }
View Full Code Here

TOP

Related Classes of com.centraview.common.CVDal

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.