use of com.zimbra.cs.redolog.op.CreateContact in project zm-mailbox by Zimbra.
the class Mailbox method createContact.
public Contact createContact(OperationContext octxt, ParsedContact pc, int folderId, String[] tags) throws ServiceException {
StoreManager sm = StoreManager.getInstance();
StagedBlob staged = null;
if (pc.hasAttachment()) {
// write the contact content directly to the mailbox's blob staging area
InputStream is = null;
try {
staged = sm.stage(is = pc.getContentStream(), (int) pc.getSize(), this);
} catch (IOException ioe) {
throw ServiceException.FAILURE("could not save contact blob", ioe);
} finally {
ByteUtil.closeStream(is);
}
}
CreateContact redoRecorder = new CreateContact(mId, folderId, pc, tags);
boolean success = false;
try {
beginTransaction("createContact", octxt, redoRecorder);
CreateContact redoPlayer = (CreateContact) currentChange().getRedoPlayer();
boolean isRedo = redoPlayer != null;
Tag.NormalizedTags ntags = new Tag.NormalizedTags(this, tags);
int contactId = getNextItemId(isRedo ? redoPlayer.getContactId() : ID_AUTO_INCREMENT);
MailboxBlob mblob = null;
if (pc.hasAttachment()) {
try {
mblob = sm.renameTo(staged, this, contactId, getOperationChangeID());
markOtherItemDirty(mblob);
} catch (IOException ioe) {
throw ServiceException.FAILURE("could not save contact blob", ioe);
}
}
int flags = 0;
Contact con = Contact.create(contactId, getFolderById(folderId), mblob, pc, flags, ntags, null);
redoRecorder.setContactId(contactId);
index.add(con);
success = true;
return con;
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
use of com.zimbra.cs.redolog.op.CreateContact in project zm-mailbox by Zimbra.
the class Mailbox method createAutoContact.
/**
* Creates new contacts in AUTO_CONTACTS folder.
* Note: Its upto the caller to check whether the email addresses in the list pre-exist.
*
* @param octxt operation context
* @param addrs email addresses
* @return newly created contacts
*/
public List<Contact> createAutoContact(OperationContext octxt, Collection<InternetAddress> addrs) throws IOException {
if (addrs.isEmpty()) {
return Collections.emptyList();
}
List<Contact> result = new ArrayList<Contact>(addrs.size());
String locale = octxt != null && octxt.getAuthenticatedUser() != null ? octxt.getAuthenticatedUser().getPrefLocale() : null;
boolean nameFormatLastFirst = false;
if (locale != null && locale.equals("ja")) {
nameFormatLastFirst = true;
}
for (InternetAddress addr : addrs) {
ZimbraLog.mailbox.debug("Auto-adding new contact addr=%s", addr);
try {
result.add(createContact(octxt, new ParsedContact(new ParsedAddress(addr, nameFormatLastFirst).getAttributes()), Mailbox.ID_FOLDER_AUTO_CONTACTS, null));
} catch (ServiceException e) {
if (e.getCode().equals(MailServiceException.TOO_MANY_CONTACTS)) {
ZimbraLog.mailbox.warn("Aborting contact addition, " + "Failed to auto-add contact addr=%s", addr, e);
return result;
}
ZimbraLog.mailbox.warn("Failed to auto-add contact addr=%s", addr, e);
}
}
return result;
}
Aggregations