use of com.zimbra.cs.mime.ParsedContact 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.mime.ParsedContact in project zm-mailbox by Zimbra.
the class Mailbox method modifyContact.
public void modifyContact(OperationContext octxt, int contactId, ParsedContact pc) 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(), pc.getSize(), this);
} catch (IOException ioe) {
throw ServiceException.FAILURE("could not save contact blob", ioe);
} finally {
ByteUtil.closeStream(is);
}
}
ModifyContact redoRecorder = new ModifyContact(mId, contactId, pc);
boolean success = false;
try {
beginTransaction("modifyContact", octxt, redoRecorder);
Contact con = getContactById(contactId);
if (!checkItemChangeID(con)) {
throw MailServiceException.MODIFY_CONFLICT();
}
try {
// setContent() calls reanalyze(), which also updates the contact fields even when there is no blob
con.setContent(staged, pc);
} catch (IOException ioe) {
throw ServiceException.FAILURE("could not save contact blob", ioe);
}
index.add(con);
success = true;
} finally {
endTransaction(success);
sm.quietDelete(staged);
}
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class TestContactGroup method derefContact.
@Test
public void derefContact() throws Exception {
Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
//TODO
OperationContext octxt = null;
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_fileAs, ContactConstants.FA_FIRST_LAST);
fields.put(ContactConstants.A_firstName, "test");
fields.put(ContactConstants.A_email, "test1@zimbra.com");
fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
Contact contact = mbox.createContact(octxt, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, "" + contact.getId()), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
contactGroup.derefAllMembers(mbox, octxt);
boolean gotContactRefMember = false;
String prevMemberKey = null;
for (Member member : contactGroup.getDerefedMembers()) {
String memberKey = member.getDerefedKey();
if (prevMemberKey != null) {
assertTrue(prevMemberKey.compareTo(memberKey) < 0);
}
prevMemberKey = memberKey;
Member.Type type = member.getType();
if (type == Member.Type.CONTACT_REF) {
assertEquals("test", memberKey);
gotContactRefMember = true;
}
// System.out.println(memberKey);
}
List<String> emailAddrs = contactGroup.getEmailAddresses(false, mbox, octxt, false);
assertEquals(4, emailAddrs.size());
assertTrue(emailAddrs.contains("test1@zimbra.com"));
assertTrue(emailAddrs.contains("test2@zimbra.com"));
assertTrue(emailAddrs.contains("aaa@test.com"));
assertTrue(emailAddrs.contains("zzz@test.com"));
assertTrue(gotContactRefMember);
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class TestContactGroup method returnMembersAsDlist.
@Test
public void returnMembersAsDlist() throws Exception {
Account account = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user1"));
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
//TODO
OperationContext octxt = null;
Map<String, Object> fields = new HashMap<String, Object>();
fields.put(ContactConstants.A_fileAs, ContactConstants.FA_FIRST_LAST);
fields.put(ContactConstants.A_firstName, "test");
fields.put(ContactConstants.A_email, "test1@zimbra.com");
fields.put(ContactConstants.A_workEmail1, "test2@zimbra.com");
Contact contact = mbox.createContact(octxt, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
Account galMember = Provisioning.getInstance().get(AccountBy.name, TestUtil.getAddress("user2"));
LdapAccount ldapAccount = (LdapAccount) galMember;
String dn = ldapAccount.getDN();
String galEntryEmail = galMember.getName();
ContactGroup contactGroup = createContactGroup(new MemberData[] { new MemberData(Member.Type.CONTACT_REF, "" + contact.getId()), new MemberData(Member.Type.GAL_REF, dn), new MemberData(Member.Type.INLINE, "aaa@test.com"), new MemberData(Member.Type.INLINE, "zzz@test.com") });
contactGroup.derefAllMembers(mbox, octxt);
for (Member member : contactGroup.getDerefedMembers()) {
String memberKey = member.getDerefedKey();
System.out.println(memberKey);
}
String dlist = contactGroup.migrateToDlist(mbox, octxt);
// should be in member order
assertEquals("test1@zimbra.com, test2@zimbra.com, " + galEntryEmail + ", aaa@test.com, zzz@test.com", dlist);
}
use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.
the class ModifyContact method redo.
@Override
public void redo() throws ServiceException {
Mailbox mailbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
InputStream in = null;
try {
in = getAdditionalDataStream();
ParsedContact pc = new ParsedContact(mFields, in);
mailbox.modifyContact(getOperationContext(), mId, pc);
} catch (IOException e) {
throw ServiceException.FAILURE("Redo error", e);
} finally {
ByteUtil.closeStream(in);
}
}
Aggregations