Search in sources :

Example 26 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class GetVolume method handle.

private GetVolumeResponse handle(GetVolumeRequest req, Map<String, Object> ctx) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(ctx);
    checkRight(zsc, ctx, Provisioning.getInstance().getLocalServer(), Admin.R_manageVolume);
    Volume vol = VolumeManager.getInstance().getVolume(req.getId());
    GetVolumeResponse resp = new GetVolumeResponse(vol.toJAXB());
    return resp;
}
Also used : Volume(com.zimbra.cs.volume.Volume) GetVolumeResponse(com.zimbra.soap.admin.message.GetVolumeResponse) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Example 27 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class DbVolume method getAll.

/**
     * Return all {@link Volume} entries in a map, where ID is the key and a {@link Volume} object is the value.
     */
public static Map<Short, Volume> getAll(DbConnection conn) throws ServiceException {
    PreparedStatement stmt = null;
    ResultSet rs = null;
    Map<Short, Volume> result = new HashMap<Short, Volume>();
    try {
        stmt = conn.prepareStatement("SELECT * FROM volume");
        rs = stmt.executeQuery();
        while (rs.next()) {
            Volume v = constructVolume(rs);
            result.put(v.getId(), v);
        }
    } catch (SQLException e) {
        throw ServiceException.FAILURE("getting all volume entries", e);
    } finally {
        DbPool.closeResults(rs);
        DbPool.closeStatement(stmt);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Volume(com.zimbra.cs.volume.Volume) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 28 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method deleteBlobRef.

@Test
public void deleteBlobRef() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false), opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
    String digest = msg.getBlob().getDigest();
    String path = msg.getBlob().getLocalBlob().getFile().getPath();
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(1, blobs.size());
    Assert.assertEquals(path, getPath(blobs.get(0)));
    DbVolumeBlobs.deleteBlobRef(conn, blobs.get(0).getId());
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(0, blobs.size());
}
Also used : BlobReference(com.zimbra.cs.store.file.BlobReference) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 29 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method revisionBlobs.

@Test
public void revisionBlobs() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, String> digestToPath = new HashMap<String, String>();
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    InputStream in = new ByteArrayInputStream("testcontent".getBytes());
    ParsedDocument pd = new ParsedDocument(in, "docname", "text/plain", System.currentTimeMillis(), null, null);
    Document doc = mbox.createDocument(null, Mailbox.ID_FOLDER_BRIEFCASE, pd, MailItem.Type.DOCUMENT, 0);
    digestToPath.put(doc.getDigest(), doc.getBlob().getLocalBlob().getFile().getPath());
    int baseId = doc.getId();
    for (int i = 0; i < 10; i++) {
        in = new ByteArrayInputStream(("testcontent-new-" + i).getBytes());
        pd = new ParsedDocument(in, "docname", "text/plain", System.currentTimeMillis(), null, null);
        doc = mbox.addDocumentRevision(null, baseId, pd);
        digestToPath.put(doc.getDigest(), doc.getBlob().getLocalBlob().getFile().getPath());
    }
    Iterable<MailboxBlobInfo> allBlobs = null;
    allBlobs = DbMailItem.getAllBlobs(conn, mbox.getSchemaGroupId(), vol.getId(), -1, -1);
    for (MailboxBlobInfo info : allBlobs) {
        DbVolumeBlobs.addBlobReference(conn, info);
    }
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, vol);
    Assert.assertEquals(digestToPath.size(), blobs.size());
    for (BlobReference blob : blobs) {
        String path = digestToPath.remove(blob.getDigest());
        Assert.assertNotNull(path);
        Assert.assertEquals(path, getPath(blob));
    }
    Assert.assertTrue(digestToPath.isEmpty());
}
Also used : BlobReference(com.zimbra.cs.store.file.BlobReference) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Document(com.zimbra.cs.mailbox.Document) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) MailboxBlobInfo(com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedDocument(com.zimbra.cs.mime.ParsedDocument) Volume(com.zimbra.cs.volume.Volume) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 30 with Volume

use of com.zimbra.cs.volume.Volume in project zm-mailbox by Zimbra.

the class DbVolumeBlobsTest method blobsByMbox.

@Test
public void blobsByMbox() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions opt = new DeliveryOptions();
    opt.setFolderId(Mailbox.ID_FOLDER_INBOX);
    ParsedMessage pm = new ParsedMessage("From: from1@zimbra.com\r\nTo: to1@zimbra.com".getBytes(), false);
    Message msg = mbox.addMessage(null, pm, opt, null);
    Volume vol = VolumeManager.getInstance().getCurrentMessageVolume();
    DbVolumeBlobs.addBlobReference(conn, mbox, vol, msg);
    String digest = msg.getBlob().getDigest();
    String path = msg.getBlob().getLocalBlob().getFile().getPath();
    List<BlobReference> blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(1, blobs.size());
    Assert.assertEquals(path, getPath(blobs.get(0)));
    Account acct2 = Provisioning.getInstance().getAccount("test2@zimbra.com");
    Mailbox mbox2 = MailboxManager.getInstance().getMailboxByAccount(acct2);
    Message msg2 = mbox2.addMessage(null, pm, opt, null);
    DbVolumeBlobs.addBlobReference(conn, mbox2, vol, msg2);
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Set<String> paths = new HashSet<String>();
    paths.add(path);
    paths.add(msg2.getBlob().getLocalBlob().getFile().getPath());
    Assert.assertEquals(2, blobs.size());
    for (BlobReference ref : blobs) {
        Assert.assertTrue(paths.remove(getPath(ref)));
    }
    Assert.assertTrue(paths.isEmpty());
    DbVolumeBlobs.deleteBlobRef(conn, mbox);
    blobs = DbVolumeBlobs.getBlobReferences(conn, digest, vol);
    Assert.assertEquals(1, blobs.size());
    BlobReference ref = blobs.get(0);
    path = msg2.getBlob().getLocalBlob().getFile().getPath();
    Assert.assertEquals(path, getPath(ref));
    Assert.assertEquals(mbox2.getId(), ref.getMailboxId());
}
Also used : Account(com.zimbra.cs.account.Account) BlobReference(com.zimbra.cs.store.file.BlobReference) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Volume(com.zimbra.cs.volume.Volume) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Volume (com.zimbra.cs.volume.Volume)36 Mailbox (com.zimbra.cs.mailbox.Mailbox)17 Test (org.junit.Test)14 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)11 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)11 Message (com.zimbra.cs.mailbox.Message)10 BlobReference (com.zimbra.cs.store.file.BlobReference)9 MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)7 VolumeManager (com.zimbra.cs.volume.VolumeManager)7 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)7 File (java.io.File)5 HashMap (java.util.HashMap)5 StoreManager (com.zimbra.cs.store.StoreManager)3 FileBlobStore (com.zimbra.cs.store.file.FileBlobStore)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 DbConnection (com.zimbra.cs.db.DbPool.DbConnection)2 Document (com.zimbra.cs.mailbox.Document)2 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)2