Beispiel #1
0
 protected void setValueBlob(T state, Blob blob) throws PropertyException {
   BlobInfo blobInfo = new BlobInfo();
   if (blob != null) {
     BlobManager blobManager = Framework.getService(BlobManager.class);
     try {
       blobInfo.key = blobManager.writeBlob(blob, this);
     } catch (IOException e) {
       throw new PropertyException("Cannot get blob info for: " + blob, e);
     }
     blobInfo.filename = blob.getFilename();
     blobInfo.mimeType = blob.getMimeType();
     blobInfo.encoding = blob.getEncoding();
     blobInfo.digest = blob.getDigest();
     blobInfo.length = blob.getLength() == -1 ? null : Long.valueOf(blob.getLength());
   }
   setBlobInfo(state, blobInfo);
 }
  protected DocumentModel doCreateLeafNode(DocumentModel parent, SourceNode node)
      throws IOException {
    if (!shouldImportDocument(node)) {
      return null;
    }
    Stopwatch stopwatch = SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.create_leaf");
    Split split = stopwatch.start();
    DocumentModel leaf = null;
    try {
      leaf = getFactory().createLeafNode(session, parent, node);
    } catch (IOException e) {
      String errMsg =
          "Unable to create leaf document for "
              + node.getSourcePath()
              + ":"
              + e
              + (e.getCause() != null ? e.getCause() : "");
      fslog(errMsg, true);
      log.error(errMsg);
      // Process leaf node creation error and check if the global
      // import task should continue
      boolean shouldImportTaskContinue =
          getFactory().processLeafNodeCreationError(session, parent, node);
      if (!shouldImportTaskContinue) {
        throw new NuxeoException(e);
      }
    } finally {
      split.stop();
    }
    BlobHolder bh = node.getBlobHolder();
    if (leaf != null && bh != null) {
      Blob blob = bh.getBlob();
      if (blob != null) {
        long fileSize = blob.getLength();
        String fileName = blob.getFilename();
        if (fileSize > 0) {
          long kbSize = fileSize / 1024;
          String parentPath = (parent == null) ? "null" : parent.getPathAsString();
          fslog(
              "Created doc "
                  + leaf.getName()
                  + " at "
                  + parentPath
                  + " with file "
                  + fileName
                  + " of size "
                  + kbSize
                  + "KB",
              true);
        }
        uploadedKO += fileSize;
      }

      // save session if needed
      commit();
    }
    return leaf;
  }
  private void emailEnglishAssertions(String filePath) throws Exception {
    // initialize mailboxes
    getPersonalMailbox("jdoe");

    injectEmail(filePath);
    DocumentRef dayRef = new PathRef(CaseConstants.CASE_ROOT_DOCUMENT_PATH + "/2009/03/17");
    assertTrue(session.exists(dayRef));
    DocumentModelList envelopes = session.getChildren(dayRef, MailConstants.MAIL_ENVELOPE_TYPE);
    assertEquals(1, envelopes.size());

    DocumentModel envelopeDoc = envelopes.get(0);
    Case envelope = envelopeDoc.getAdapter(Case.class);
    List<DocumentModel> linkedDocs = envelope.getDocuments();
    assertEquals(2, linkedDocs.size());
    DocumentModel firstDoc = linkedDocs.get(0);

    String title = (String) firstDoc.getPropertyValue(CaseConstants.TITLE_PROPERTY_NAME);
    assertEquals("[Fwd: RENOUVELLEMENT DE SUPPORT ANNUEL NUXEO]", title);
    Calendar originalReceptionDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_IMPORT_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Wed, 14 Jan 2009 15:15:25 +0100").getTime(),
        originalReceptionDate.getTime().getTime());
    Calendar receptionDate =
        (Calendar) firstDoc.getPropertyValue(CaseConstants.DOCUMENT_RECEIVE_DATE_PROPERTY_NAME);
    assertEquals(
        emailDateParser.parse("Tue, 17 Mar 2009 13:39:05 +0100").getTime(),
        receptionDate.getTime().getTime());

    Contacts senders = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_SENDERS);
    assertNotNull(senders);
    assertEquals(1, senders.size());
    Contact sender = senders.get(0);
    assertEquals("Sylvie KAPCOM", sender.getName());
    assertEquals("*****@*****.**", sender.getEmail());

    Contacts recipients = Contacts.getContactsForDoc(firstDoc, CaseConstants.CONTACTS_PARTICIPANTS);
    assertNotNull(recipients);
    assertEquals(2, recipients.size());

    assertEquals("*****@*****.**", recipients.get(0).getEmail());

    assertTrue(
        (recipients.get(1).getName() == null) || ("".equals(recipients.get(1).getName().trim())));
    assertEquals("*****@*****.**", recipients.get(1).getEmail());

    // testing content
    DocumentModel secondDoc = linkedDocs.get(1);
    Blob fileBlob = (Blob) secondDoc.getPropertyValue(CaseConstants.FILE_PROPERTY_NAME);

    assertEquals("The file blob filename is", "testpdf.pdf", fileBlob.getFilename());
    assertEquals("the file blob length is", 24016, fileBlob.getLength());

    String fileNamePropertyValue =
        (String) secondDoc.getPropertyValue(CaseConstants.FILENAME_PROPERTY_NAME);
    assertEquals("The filename property value is", "testpdf.pdf", fileNamePropertyValue);
  }
  @Test
  public void ensureDigestDecode() throws IOException, StorageException {
    Blob blob = Blobs.createBlob(CONTENT2);
    String contentMd5;
    try (InputStream is = blob.getStream()) {
      StreamMd5AndLength md5 =
          Utility.analyzeStream(is, blob.getLength(), 2 * Constants.MB, true, true);
      contentMd5 = md5.getMd5();
    }

    assertTrue(AzureFileStorage.isBlobDigestCorrect(CONTENT2_MD5, contentMd5));
  }
  protected void writeBlobProperty(JsonGenerator jg, Property prop) throws IOException {
    Blob blob = (Blob) prop.getValue();
    if (blob == null) {
      jg.writeNull();
      return;
    }
    jg.writeStartObject();
    String v = blob.getFilename();
    if (v == null) {
      jg.writeNullField("name");
    } else {
      jg.writeStringField("name", v);
    }
    v = blob.getMimeType();
    if (v == null) {
      jg.writeNullField("mime-type");
    } else {
      jg.writeStringField("mime-type", v);
    }
    v = blob.getEncoding();
    if (v == null) {
      jg.writeNullField("encoding");
    } else {
      jg.writeStringField("encoding", v);
    }
    v = blob.getDigest();
    if (v == null) {
      jg.writeNullField("digest");
    } else {
      jg.writeStringField("digest", v);
    }
    jg.writeStringField("length", Long.toString(blob.getLength()));

    String blobUrl = getBlobUrl(prop);
    if (blobUrl == null) {
      blobUrl = "";
    }
    jg.writeStringField("data", blobUrl);
    jg.writeEndObject();
  }
Beispiel #6
0
 @Override
 public TemplateModel get(String name) throws TemplateModelException {
   try {
     if (blob != null) {
       if (keys[0].equals(name)) {
         return new SimpleScalar(blob.getFilename());
       } else if (keys[1].equals(name)) {
         return new SimpleScalar(blob.getString());
       } else if (keys[2].equals(name)) {
         return new SimpleNumber(blob.getLength());
       } else if (keys[3].equals(name)) {
         return new SimpleScalar(blob.getMimeType());
       } else if (keys[4].equals(name)) {
         return new SimpleScalar(blob.getEncoding());
       } else if (keys[5].equals(name)) {
         return new SimpleScalar(blob.getDigest());
       }
     }
     return NOTHING;
   } catch (IOException e) {
     throw new TemplateModelException(e);
   }
 }
Beispiel #7
0
 @Override
 public TemplateCollectionModel values() throws TemplateModelException {
   try {
     List<Object> list = new ArrayList<Object>(keys.length);
     if (blob != null) {
       list.add(blob.getFilename());
       list.add(blob.getString());
       list.add(blob.getLength());
       list.add(blob.getMimeType());
       list.add(blob.getEncoding());
       list.add(blob.getDigest());
     } else {
       list.add("");
       list.add("");
       list.add("");
       list.add("");
       list.add("");
       list.add("");
     }
     return (TemplateCollectionModel) wrapper.wrap(list);
   } catch (IOException e) {
     throw new TemplateModelException("Failed to adapt complex property values", e);
   }
 }