use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class TestDocumentServer method testDeleteRevisions.
/**
* Server-side test that confirms that all blobs are cleaned up when
* a document with multiple revisions is deleted.
*/
@Test
public void testDeleteRevisions() throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
// Create first revision.
String content = "one";
ParsedDocument pd = new ParsedDocument(new ByteArrayInputStream(content.getBytes()), NAME_PREFIX + "-testDeleteRevisions.txt", "text/plain", System.currentTimeMillis(), USER_NAME, "one", true);
Document doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
int docId = doc.getId();
MailItem.Type type = doc.getType();
File blobDir = getBlobDir(doc);
List<Document> revisions = mbox.getAllRevisions(null, docId, type);
Assert.assertEquals(1, revisions.size());
if (TestUtil.checkLocalBlobs()) {
Assert.assertEquals(1, getBlobCount(blobDir, docId));
}
Assert.assertEquals(true, doc.isDescriptionEnabled());
// Add a second revision.
content = "two";
pd = new ParsedDocument(new ByteArrayInputStream(content.getBytes()), NAME_PREFIX + "-testDeleteRevisions2.txt", "text/plain", System.currentTimeMillis(), USER_NAME, "two", false);
doc = mbox.addDocumentRevision(null, docId, pd);
Assert.assertEquals(2, mbox.getAllRevisions(null, docId, type).size());
if (TestUtil.checkLocalBlobs()) {
Assert.assertEquals(2, getBlobCount(blobDir, docId));
}
Assert.assertEquals(false, doc.isDescriptionEnabled());
// Move to trash, empty trash, and confirm that both blobs were deleted.
mbox.move(null, doc.getId(), doc.getType(), Mailbox.ID_FOLDER_TRASH);
mbox.emptyFolder(null, Mailbox.ID_FOLDER_TRASH, false);
mbox.emptyDumpster(null);
if (TestUtil.checkLocalBlobs()) {
Assert.assertEquals(0, getBlobCount(blobDir, docId));
}
}
use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class Document method reanalyze.
@Override
public void reanalyze(Object obj, long newSize) throws ServiceException {
if (!(obj instanceof ParsedDocument)) {
throw ServiceException.FAILURE("cannot reanalyze non-ParsedDocument object", null);
}
if (mData.isSet(Flag.FlagInfo.UNCACHED)) {
throw ServiceException.FAILURE("cannot reanalyze an old item revision", null);
}
ParsedDocument pd = (ParsedDocument) obj;
// new revision has at least new date.
markItemModified(Change.METADATA);
// new revision might have new name.
if (!mData.name.equals(pd.getFilename())) {
markItemModified(Change.NAME);
}
contentType = pd.getContentType();
creator = pd.getCreator();
if (!LC.documents_disable_instant_parsing.booleanValue())
fragment = pd.getFragment();
mData.date = (int) (pd.getCreatedDate() / 1000L);
mData.name = pd.getFilename();
mData.setSubject(pd.getFilename());
description = pd.getDescription();
descEnabled = pd.isDescriptionEnabled();
pd.setVersion(getVersion());
if (mData.size != pd.getSize()) {
markItemModified(Change.SIZE);
mMailbox.updateSize(pd.getSize() - mData.size, false);
getFolder().updateSize(0, 0, pd.getSize() - mData.size);
mData.size = pd.getSize();
}
saveData(new DbMailItem(mMailbox));
}
use of com.zimbra.cs.mime.ParsedDocument in project zm-mailbox by Zimbra.
the class SaveDocument method createDocument.
protected Document createDocument(Doc doc, ZimbraSoapContext zsc, OperationContext octxt, Mailbox mbox, Element docElem, InputStream is, int folderId, MailItem.Type type, MailItem parent, CustomMetadata custom, boolean index) throws ServiceException {
Document docItem = null;
if (doc.name == null || doc.name.trim().equals("")) {
throw ServiceException.INVALID_REQUEST("missing required attribute: " + MailConstants.A_NAME, null);
} else if (doc.contentType == null || doc.contentType.trim().equals("")) {
throw ServiceException.INVALID_REQUEST("missing required attribute: " + MailConstants.A_CONTENT_TYPE, null);
}
boolean descEnabled = false;
String flags = "";
if (docElem != null) {
descEnabled = docElem.getAttributeBool(MailConstants.A_DESC_ENABLED, true);
flags = docElem.getAttribute(MailConstants.A_FLAGS, null);
}
try {
ParsedDocument pd = new ParsedDocument(is, doc.name, doc.contentType, System.currentTimeMillis(), getAuthor(zsc), doc.description, descEnabled);
docItem = mbox.createDocument(octxt, folderId, pd, type, Flag.toBitmask(flags), parent, custom, index);
} catch (IOException e) {
throw ServiceException.FAILURE("unable to create document", e);
}
return docItem;
}
Aggregations