Package com.centraview.file

Examples of com.centraview.file.CvFileFacade


      int fileID = 0;
      if(fileId != null && !fileId.equals("")&& !fileId.equals("null")){
        fileID = Integer.parseInt(fileId);
      }//end of if(fileId != null && !fileId.equals("")&& !fileId.equals("null"))
      if(fileID > 0){
      CvFileFacade fileFacade = new CvFileFacade();

      HashMap imageInfo = fileFacade.getFileInputStream(individualID, fileID, dataSource);
      byte[] buffer = (byte[])imageInfo.get("imageBuffer");
      String fileName = (String)imageInfo.get("fileName");
      int size = 0;
      if(buffer != null){
        size = buffer.length;
View Full Code Here


          cvdal.setSqlQuery(attachmentQuery);
          cvdal.setInt(1, messageNumberID.intValue());
          Collection attachmentResults = cvdal.executeQuery();
          if (attachmentResults != null) {
            Iterator attachmentIterator = attachmentResults.iterator();
            CvFileFacade fileFacade = new CvFileFacade();

            while (attachmentIterator.hasNext()) {
              HashMap attachmentHashMap = (HashMap) attachmentIterator.next();
              Number attachmentID = (Number) attachmentHashMap.get("FileID");
              // Reason for providing -13 because we don't want to carry out the Authorization Step
              // We don't have to do the authorization check from here..
              // Thats why passing -13. So that we will avoid the authorization..

              CvFileVO attachment = fileFacade.getFile(-13, attachmentID.intValue(), this.dataSource);
              mailMessageVO.addAttachedFiles(attachment);
            }
          }   // end while (attachmentIterator.hasNext())
        }   // end if (resultsIterator.hasNext())
      // end if (resultsCollection != null)
View Full Code Here

   * @throws Exception Anything that may have gone awry,
   */
  private int deleteMessageAttachments(int individualID, int messageID, CVDal cvdal)
  {
    int numberDeleted = 0;
    CvFileFacade fileFacade = new CvFileFacade();
    CvFolderVO attachmentFolder = getAttachmentFolder(individualID);

    String selectQuery = "SELECT AttachmentID, FileID FROM attachment WHERE MessageID = ?";
    cvdal.setSqlQuery(selectQuery);
    cvdal.setInt(1, messageID);

    Collection resultsCollection = cvdal.executeQuery();
    cvdal.setSqlQueryToNull();

    String deleteQuery = "DELETE FROM attachment WHERE AttachmentID = ?";
    cvdal.setSqlQuery(deleteQuery);

    if (resultsCollection != null) {
      Iterator resultsIterator = resultsCollection.iterator();
      while (resultsIterator.hasNext()) {
        HashMap resultsHashMap = (HashMap) resultsIterator.next();
        Number fileID = (Number) resultsHashMap.get("FileID");
        Number attachmentID = (Number) resultsHashMap.get("AttachmentID");
        try {
          fileFacade.deleteFile(individualID, fileID.intValue(), attachmentFolder.getFolderId(), this.dataSource);
        } catch (Exception e) {
          logger.error("Exception in deleteMessageAttachments");
          e.printStackTrace();
        }

View Full Code Here

   */
  public int createAttachmentFolder(int individualID)
  {
    int newFolderID = -1;
    try {
      CvFileFacade fileFacade = new CvFileFacade();
      CvFolderVO homeFolderVO = fileFacade.getHomeFolder(individualID, this.dataSource);

      CvFolderVO attachmentFolderVO = new CvFolderVO();
      attachmentFolderVO.setCreatedBy(individualID);
      attachmentFolderVO.setDescription("Email Attachments are kept here.");
      attachmentFolderVO.setOwner(individualID);
      attachmentFolderVO.setName(CvFolderVO.EMAIL_ATTACHMENT_FOLDER);
      attachmentFolderVO.setParent(homeFolderVO.getFolderId());

      try {
        newFolderID = fileFacade.addFolder(individualID, attachmentFolderVO, this.dataSource);
      }catch(CvFileException cfe){
        cfe.printStackTrace();
        // TODO: what the hell do we do if we could not create the attachments folder?
      }
    }catch(Exception e){
View Full Code Here

   * @return The number of attachments added for this message.
   */
  private int saveAttachments(Object messageContent, int messageID, int accountID, int ownerID, int attachmentFolderID, CVDal cvdal, HashMap embededImageMap)
  {
    int numberOfAttachments = 0;
    CvFileFacade fileFacade = new CvFileFacade();

    try {
      if (messageContent instanceof Multipart) {
        // we only process the attachments from Multipart messages
        Multipart multipart = (Multipart) messageContent;

        String insertQuery = "INSERT INTO attachment (MessageID, FileName, FileID) VALUES(?, ?, ?)";
        cvdal.setSqlQuery(insertQuery);

        for (int i = 0; i < multipart.getCount(); i++) {
          // loop through the parts, processing each one...
          Part part = (Part) multipart.getBodyPart(i);
          String contentType = part.getContentType();
          String disposition = part.getDisposition();

          if (disposition != null && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition.equalsIgnoreCase(Part.INLINE))) {
            // by SPEC, we should only save those parts whose disposition is "attachment" or "inline".
            // disposition == null means that it is a content part (message body, readable content)
            CvFileVO attachment = new CvFileVO();

            String filename = (part.getFileName() != null) ? (String)part.getFileName() : "Part-" + i;

            // prepend human readable date to the fileName. This is for uniqueness.
            SimpleDateFormat df = new SimpleDateFormat("MMMM_dd_yyyy_hh_mm_ss_S");
            String prependDate = df.format(new Date());
            attachment.setName(prependDate + "-" + filename);
            attachment.setTitle(filename);
            attachment.setOwner(ownerID);
            attachment.setAuthorId(ownerID);
            attachment.setCreatedBy(ownerID);
            attachment.setDescription("Email Attachment: " + filename);
            attachment.setPhysical(CvFileVO.FP_PHYSICAL);

            if (attachment.getTitle() == null || (attachment.getTitle()).length() <= 0) {
              // this is not good, and we should never reach this point, because I
              // have added some fail-proof default content for filename above
              return -1;
            }

            int newFileID = fileFacade.addFile(ownerID, attachmentFolderID, attachment, part.getInputStream(), this.dataSource);

            if (newFileID > 0) {
              cvdal.clearParameters();
              cvdal.setInt(1, messageID);
              cvdal.setString(2, attachment.getTitle());
              cvdal.setInt(3, newFileID);
              int rowsAffected = cvdal.executeUpdate();
            }

            numberOfAttachments++;
          }else if(contentType != null && contentType.toLowerCase().indexOf("rfc822") > -1){
            // The attachment is itself an rfc822 message. Therefore, we need to
            // create a new MailMessage object, and process all its parts too
            this.saveAttachments(this.getPartContent(part), messageID, accountID, ownerID, attachmentFolderID, cvdal, embededImageMap);
          } else if (contentType != null && (contentType.length() >= 10) && ((contentType.toLowerCase().substring(0, 10)).indexOf("image") != -1)) {
            // The attachment is itself an rfc2387 message. Therefore, we need to
            // create a new MailMessage object, and process all the embeded image parts too
            CvFileVO attachment = new CvFileVO();

            String contentID = null;
      String partContentID[] = part.getHeader("Content-ID");
      if(partContentID != null && partContentID.length != 0){
        contentID = partContentID[0];
      }
            String filename = (part.getFileName() != null) ? (String)part.getFileName() : "Part-" + i;

            // prepend human readable date to the fileName. This is for uniqueness.
            SimpleDateFormat df = new SimpleDateFormat("MMMM_dd_yyyy_hh_mm_ss_S");
            String prependDate = df.format(new Date());
            String storedFileName = prependDate + "-" + filename;
            attachment.setName(storedFileName);
            attachment.setTitle(filename);
      attachment.setOwner(ownerID);
            attachment.setAuthorId(ownerID);
            attachment.setCreatedBy(ownerID);
            attachment.setDescription("Email Attachment: " + filename);
            attachment.setPhysical(CvFileVO.FP_PHYSICAL);

            if (attachment.getTitle() == null || (attachment.getTitle()).length() <= 0) {
              // this is not good, and we should never reach this point, because I
              // have added some fail-proof default content for filename above
              return -1;
            }

            int newFileID = fileFacade.addFile(ownerID, attachmentFolderID, attachment, part.getInputStream(), this.dataSource);

            if (newFileID > 0) {
              //According to rfc. Some email client will not add the less than and greather than in the content-ID
              //We will replace lessthen and greaterthen with blank
              contentID = contentID.replaceAll("<","");
View Full Code Here

          // get individualID for user we are deleting
          int deleteIndividualId = remote.getIndividualIdForUser(elementID);
          logger.debug("Got individual ID for user: [" + deleteIndividualId + "]");

          try {
            CvFileFacade cvf = new CvFileFacade();
            CvFolderVO folder = cvf.getHomeFolder(deleteIndividualId, dataSource);
           
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
            String yyyymmdd = sdf.format(new java.util.Date(System.currentTimeMillis()));
           
            folder.setName(folder.getName() + "." + yyyymmdd + "." + "deleted");
            folder.setOwner(individualId);
            cvf.updateFolder(individualId, folder, dataSource);
          } catch (Exception e) {
            logger.error("Exception thrown: ", e);
          }
         
          try {
View Full Code Here

      UserObject userobjectd = (UserObject) session.getAttribute("userobject");
      int userid = userobjectd.getIndividualID();

      //Create object CVFileFacade
      CvFileFacade cvfile = new CvFileFacade();
      int literatureID = literatureForm.getLiteratureID();
      int prevFileID = literatureForm.getFileID();
      int fileID = 0;

      FormFile ff = (FormFile) literatureForm.getFile();

      if (ff.getFileSize() > 0) {
        String strf = ff.getFileName();
        InputStream im = ff.getInputStream();

        //Add file first
        CvFileVO flvo = new CvFileVO();
        flvo.setTitle("Literature"); //file name
        flvo.setName(strf);
        flvo.setCreatedBy(userid);

        fileID = cvfile.addLiterature(userid, flvo, im, dataSource);
      }

      LiteratureHome literatureHome = (LiteratureHome) CVUtility.getHomeObject("com.centraview.administration.modulesettings.LiteratureHome", "LiteratureAdmin");
      Literature remote = literatureHome.create();
      remote.setDataSource(dataSource);

      //Update the calues in the table;
      remote.updateLiterature(userid, literatureForm.getLiteratureName(), fileID, literatureID);

      //Delete the prevously uploaded file permanentaly
      if (fileID != 0) {
        cvfile.deleteLiterature(userid, prevFileID, dataSource);
      }

      //Set the attributes
      request.setAttribute("rowId", literatureID + "");
    } catch (Exception e) {
View Full Code Here

        FormFile ff = (FormFile) fileform.getFile();
        String strf = ff.getFileName();
        InputStream im = ff.getInputStream();

        CvFileFacade cvfile = new CvFileFacade();
        CvFileVO flvo = new CvFileVO();
        flvo.setTitle(strf); //file name

    Calendar c = Calendar.getInstance();
    java.util.Date dt = c.getTime();
    DateFormat df = new SimpleDateFormat("MM_dd_yyyy_hh_mm_ss");
    String dateStamp = df.format(dt);

    strf = "attachment_" + dateStamp +"_"+ strf;
        flvo.setName(strf);
        flvo.setCreatedBy(userid);
        flvo.setOwner(userid);
        flvo.setAuthorId(userid);
        flvo.setFileSize((float) ff.getFileSize());

        CvFolderVO homeFolder = cvfile.getHomeFolder(userid, dataSource);
        int xxx = cvfile.addFile(userid, homeFolder.getFolderId(), flvo, im, dataSource);
        //int xxx = cvfile.addEmailAttachment(userid, flvo, im, dataSource);

        HashMap hm = (HashMap) session.getAttribute("AttachfileList");

        if (hm == null)
View Full Code Here

      while (iter.hasNext())
      {
      fileid[x++] = Integer.parseInt((String)iter.next());
      }

      CvFileFacade cvfile = new CvFileFacade();
      if (attchmentids != null)
      {
      for (int i = 0; i < attchmentids.size(); i++)
      {
        cvfile.commitEmailAttachment(individualId, fileid[i], dataSource);
      }
      }
    }

      request.setAttribute("messageid", Integer.toString(messageid));
View Full Code Here

          break;
        }
      }
      if ( hm!= null )
      {
        CvFileFacade cvfile = new CvFileFacade();
        cvfile.deleteEmailAttachment(individualID,Integer.parseInt(key.toString()), dataSource);
        hm.remove( key );
        session.setAttribute( "AttachfileList" , hm );
      }

    } catch (Exception e)
View Full Code Here

TOP

Related Classes of com.centraview.file.CvFileFacade

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.