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));
}
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;
}
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;
}
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));
}
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;
}
Aggregations