Search in sources :

Example 11 with DbMailItem

use of com.zimbra.cs.db.DbMailItem in project zm-mailbox by Zimbra.

the class CalendarItem method reanalyze.

@Override
void reanalyze(Object data, long newSize) throws ServiceException {
    String subject = null;
    Invite firstInvite = getDefaultInviteOrNull();
    if (firstInvite != null) {
        subject = firstInvite.getName();
    }
    mData.setSubject(Strings.nullToEmpty(subject));
    saveData(new DbMailItem(mMailbox));
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 12 with DbMailItem

use of com.zimbra.cs.db.DbMailItem in project zm-mailbox by Zimbra.

the class Mailbox method getItemList.

public List<MailItem> getItemList(OperationContext octxt, MailItem.Type type, int folderId, SortBy sort) throws ServiceException {
    List<MailItem> result;
    boolean success = false;
    if (type == MailItem.Type.UNKNOWN) {
        return Collections.emptyList();
    }
    try {
        // tag/folder caches are populated in beginTransaction...
        beginReadTransaction("getItemList", octxt);
        Folder folder = folderId == -1 ? null : getFolderById(folderId);
        if (folder == null) {
            if (!hasFullAccess()) {
                throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
            }
        } else {
            if (!folder.canAccess(ACL.RIGHT_READ, getAuthenticatedAccount(), isUsingAdminPrivileges())) {
                throw ServiceException.PERM_DENIED("you do not have sufficient permissions");
            }
        }
        switch(type) {
            case FOLDER:
            case SEARCHFOLDER:
            case MOUNTPOINT:
                result = new ArrayList<MailItem>(mFolderCache.size());
                for (Folder subfolder : mFolderCache.values()) {
                    if (subfolder.getType() == type || type == MailItem.Type.FOLDER) {
                        if (folder == null || subfolder.getFolderId() == folderId) {
                            result.add(subfolder);
                        }
                    }
                }
                success = true;
                break;
            case TAG:
                if (folderId != -1 && folderId != ID_FOLDER_TAGS) {
                    return Collections.emptyList();
                }
                result = new ArrayList<MailItem>(mTagCache.size() / 2);
                for (Map.Entry<Object, Tag> entry : mTagCache.entrySet()) {
                    Tag tag = entry.getValue();
                    if (entry.getKey() instanceof String && tag.isListed()) {
                        result.add(tag);
                    }
                }
                success = true;
                break;
            case FLAG:
                if (folderId != -1 && folderId != ID_FOLDER_TAGS) {
                    return Collections.emptyList();
                }
                List<Flag> allFlags = Flag.allOf(this);
                result = new ArrayList<MailItem>(allFlags.size());
                for (Flag flag : allFlags) {
                    result.add(flag);
                }
                success = true;
                break;
            default:
                List<MailItem.UnderlyingData> dataList;
                if (folder != null) {
                    dataList = DbMailItem.getByFolder(folder, type, sort);
                } else {
                    dataList = DbMailItem.getByType(this, type, sort);
                }
                if (dataList == null) {
                    return Collections.emptyList();
                }
                result = new ArrayList<MailItem>(dataList.size());
                for (MailItem.UnderlyingData data : dataList) {
                    if (data != null) {
                        result.add(getItem(data));
                    }
                }
                // DbMailItem call handles all sorts except SORT_BY_NAME_NAT
                if (sort.getKey() == SortBy.Key.NAME_NATURAL_ORDER) {
                    sort = SortBy.NONE;
                }
                success = true;
                break;
        }
    } finally {
        endTransaction(success);
    }
    Comparator<MailItem> comp = MailItem.getComparator(sort);
    if (comp != null) {
        Collections.sort(result, comp);
    }
    return result;
}
Also used : UnderlyingData(com.zimbra.cs.mailbox.MailItem.UnderlyingData) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder) DbMailItem(com.zimbra.cs.db.DbMailItem) ZimbraMailItem(com.zimbra.common.mailbox.ZimbraMailItem) AlterItemTag(com.zimbra.cs.redolog.op.AlterItemTag) CreateTag(com.zimbra.cs.redolog.op.CreateTag) DbTag(com.zimbra.cs.db.DbTag) UnderlyingData(com.zimbra.cs.mailbox.MailItem.UnderlyingData) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentLinkedHashMap(com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap) IcalXmlStrMap(com.zimbra.cs.mailbox.calendar.IcalXmlStrMap) HashMap(java.util.HashMap) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap)

Example 13 with DbMailItem

use of com.zimbra.cs.db.DbMailItem in project zm-mailbox by Zimbra.

the class Comment method create.

public static Comment create(Mailbox mbox, MailItem parent, int id, String uuid, String text, String creatorId, CustomMetadata custom) throws ServiceException {
    if (!(parent instanceof Document))
        throw MailServiceException.CANNOT_PARENT();
    UnderlyingData data = new UnderlyingData();
    data.uuid = uuid;
    data.id = id;
    data.type = Type.COMMENT.toByte();
    data.folderId = Mailbox.ID_FOLDER_COMMENTS;
    data.parentId = parent.mId;
    data.setSubject(text);
    data.date = mbox.getOperationTimestamp();
    data.size = text.length();
    data.metadata = encodeMetadata(DEFAULT_COLOR_RGB, 1, 1, creatorId, custom);
    data.contentChanged(mbox);
    new DbMailItem(mbox).create(data);
    Comment comment = new Comment(mbox, data);
    comment.finishCreation(parent);
    return comment;
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem)

Example 14 with DbMailItem

use of com.zimbra.cs.db.DbMailItem 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));
}
Also used : ParsedDocument(com.zimbra.cs.mime.ParsedDocument) DbMailItem(com.zimbra.cs.db.DbMailItem)

Example 15 with DbMailItem

use of com.zimbra.cs.db.DbMailItem in project zm-mailbox by Zimbra.

the class Link method create.

static Link create(Folder parent, int id, String uuid, String name, String ownerId, int remoteId, CustomMetadata custom) throws ServiceException {
    if (!parent.canAccess(ACL.RIGHT_INSERT)) {
        throw ServiceException.PERM_DENIED("you do not have sufficient permissions on the parent folder");
    }
    if (!parent.canContain(Type.LINK)) {
        throw MailServiceException.CANNOT_CONTAIN();
    }
    name = validateItemName(name);
    Mailbox mbox = parent.getMailbox();
    UnderlyingData data = new UnderlyingData();
    data.uuid = uuid;
    data.id = id;
    data.type = Type.MOUNTPOINT.toByte();
    data.folderId = parent.getId();
    data.parentId = data.folderId;
    data.date = mbox.getOperationTimestamp();
    data.name = name;
    data.setSubject(name);
    data.metadata = encodeMetadata(DEFAULT_COLOR_RGB, 1, 1, ownerId, remoteId, custom);
    data.contentChanged(mbox);
    ZimbraLog.mailop.info("Adding Link %s: id=%d, parentId=%d, parentName=%s.", name, data.id, parent.getId(), parent.getName());
    new DbMailItem(mbox).create(data);
    Link link = new Link(mbox, data);
    link.finishCreation(parent);
    return link;
}
Also used : DbMailItem(com.zimbra.cs.db.DbMailItem)

Aggregations

DbMailItem (com.zimbra.cs.db.DbMailItem)20 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)4 Account (com.zimbra.cs.account.Account)3 DbTag (com.zimbra.cs.db.DbTag)3 Invite (com.zimbra.cs.mailbox.calendar.Invite)3 ZimbraMailItem (com.zimbra.common.mailbox.ZimbraMailItem)2 ParsedContact (com.zimbra.cs.mime.ParsedContact)2 ParsedDocument (com.zimbra.cs.mime.ParsedDocument)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 ConcurrentLinkedHashMap (com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap)1 ZFolder (com.zimbra.client.ZFolder)1 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)1 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)1 ServiceException (com.zimbra.common.service.ServiceException)1 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)1 IndexDocument (com.zimbra.cs.index.IndexDocument)1 CustomMetadataList (com.zimbra.cs.mailbox.MailItem.CustomMetadata.CustomMetadataList)1 UnderlyingData (com.zimbra.cs.mailbox.MailItem.UnderlyingData)1 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)1