Search in sources :

Example 1 with CreateFolder

use of com.zimbra.cs.redolog.op.CreateFolder in project zm-mailbox by Zimbra.

the class Mailbox method createFolder.

public Folder createFolder(OperationContext octxt, String name, int parentId, Folder.FolderOptions fopt) throws ServiceException {
    CreateFolder redoRecorder = new CreateFolder(mId, name, parentId, fopt);
    boolean success = false;
    try {
        beginTransaction("createFolder", octxt, redoRecorder);
        CreateFolder redoPlayer = (CreateFolder) currentChange().getRedoPlayer();
        int folderId;
        String uuid;
        if (redoPlayer == null) {
            folderId = getNextItemId(ID_AUTO_INCREMENT);
            uuid = Strings.emptyToNull(fopt.getUuid()) == null ? UUIDUtil.generateUUID() : fopt.getUuid();
        } else {
            folderId = getNextItemId(redoPlayer.getFolderId());
            uuid = redoPlayer.getFolderUuid();
        }
        Folder folder = Folder.create(folderId, uuid, this, getFolderById(parentId), name, fopt.getAttributes(), fopt.getDefaultView(), fopt.getFlags(), fopt.getColor(), fopt.getDate(), fopt.getUrl(), fopt.getCustomMetadata());
        redoRecorder.setFolderIdAndUuid(folder.getId(), folder.getUuid());
        success = true;
        updateRssDataSource(folder);
        return folder;
    } finally {
        endTransaction(success);
    }
}
Also used : CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Example 2 with CreateFolder

use of com.zimbra.cs.redolog.op.CreateFolder in project zm-mailbox by Zimbra.

the class Mailbox method createFolder.

/**
     * Creates a folder.  Implicitly creates any parent folders in <tt>path</tt> if necessary.
     *
     * @param octxt the operation context
     * @param path the slash-separated folder path
     * @param attrs the folder attributes, or <tt>0</tt> for the default attributes
     * @param defaultView the folder view, or <tt>0</tt> for the default view
     * @param flags the folder flags, or <tt>0</tt> for no flags
     * @param color the folder color, or {@link MailItem#DEFAULT_COLOR}
     * @param url the folder URL, or <tt>null</tt>
     * @return the new folder
     * @see Folder#getAttributes()
     * @see Folder#getDefaultView()
     * @see MailItem#getColor()
     *
     * @throws ServiceException if the folder creation fails
     */
public Folder createFolder(OperationContext octxt, String path, Folder.FolderOptions fopt) throws ServiceException {
    if (path == null) {
        throw ServiceException.FAILURE("null path passed to Mailbox.createFolderPath", null);
    }
    if (!path.startsWith("/")) {
        path = '/' + path;
    }
    if (path.endsWith("/") && path.length() > 1) {
        path = path.substring(0, path.length() - 1);
    }
    CreateFolderPath redoRecorder = new CreateFolderPath(mId, path, fopt);
    boolean success = false;
    try {
        beginTransaction("createFolderPath", octxt, redoRecorder);
        CreateFolderPath redoPlayer = (CreateFolderPath) currentChange().getRedoPlayer();
        String[] parts = path.substring(1).split("/");
        if (parts.length == 0) {
            throw MailServiceException.ALREADY_EXISTS(path);
        }
        int[] recorderFolderIds = new int[parts.length];
        String[] recorderFolderUuids = new String[parts.length];
        int[] playerFolderIds = redoPlayer == null ? null : redoPlayer.getFolderIds();
        String[] playerFolderUuids = redoPlayer == null ? null : redoPlayer.getFolderUuids();
        if (playerFolderIds != null && playerFolderIds.length != recorderFolderIds.length) {
            throw ServiceException.FAILURE("incorrect number of path segment ids in redo player", null);
        }
        if (playerFolderUuids != null && playerFolderUuids.length != recorderFolderUuids.length) {
            throw ServiceException.FAILURE("incorrect number of path segment uuids in redo player", null);
        }
        Folder folder = getFolderById(ID_FOLDER_USER_ROOT);
        for (int i = 0; i < parts.length; i++) {
            boolean last = i == parts.length - 1;
            int folderId = playerFolderIds == null ? ID_AUTO_INCREMENT : playerFolderIds[i];
            String folderUuid = playerFolderUuids == null ? UUIDUtil.generateUUID() : playerFolderUuids[i];
            Folder subfolder = folder.findSubfolder(parts[i]);
            if (subfolder == null) {
                subfolder = Folder.create(getNextItemId(folderId), folderUuid, this, folder, parts[i], fopt.getAttributes(), last ? fopt.getDefaultView() : MailItem.Type.UNKNOWN, fopt.getFlags(), fopt.getColor(), fopt.getDate(), last ? fopt.getUrl() : null, fopt.getCustomMetadata());
            } else if (folderId != ID_AUTO_INCREMENT && folderId != subfolder.getId()) {
                throw ServiceException.FAILURE("parent folder id changed since operation was recorded", null);
            } else if (last) {
                throw MailServiceException.ALREADY_EXISTS(path);
            }
            recorderFolderIds[i] = subfolder.getId();
            recorderFolderUuids[i] = subfolder.getUuid();
            folder = subfolder;
        }
        redoRecorder.setFolderIdsAndUuids(recorderFolderIds, recorderFolderUuids);
        success = true;
        return folder;
    } finally {
        endTransaction(success);
    }
}
Also used : CreateFolderPath(com.zimbra.cs.redolog.op.CreateFolderPath) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint)

Aggregations

ZFolder (com.zimbra.client.ZFolder)2 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)2 CreateFolder (com.zimbra.cs.redolog.op.CreateFolder)2 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)2 RefreshMountpoint (com.zimbra.cs.redolog.op.RefreshMountpoint)2 CreateFolderPath (com.zimbra.cs.redolog.op.CreateFolderPath)1