Search in sources :

Example 11 with ParsedContact

use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.

the class ContactAutoCompleteTest method dash.

@Test
public void dash() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Map<String, Object> fields = new HashMap<String, Object>();
    fields.put(ContactConstants.A_firstName, "Conf - Hillview");
    fields.put(ContactConstants.A_lastName, "test.server-vmware - dash");
    fields.put(ContactConstants.A_email, "test@zimbra.com");
    mbox.createContact(null, new ParsedContact(fields), Mailbox.ID_FOLDER_CONTACTS, null);
    ContactAutoComplete autocomplete = new ContactAutoComplete(mbox.getAccount(), new OperationContext(mbox));
    Assert.assertEquals(1, autocomplete.query("conf -", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("conf - h", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("test.server-vmware -", null, 100).entries.size());
    Assert.assertEquals(1, autocomplete.query("test.server-vmware - d", null, 100).entries.size());
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 12 with ParsedContact

use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.

the class SyncTest method tags.

@Test
public void tags() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    mbox.beginTrackingSync();
    // create one tag implicitly and one explicitly
    ParsedContact pc = new ParsedContact(ImmutableMap.of(ContactConstants.A_firstName, "Bob", ContactConstants.A_lastName, "Smith"));
    mbox.createContact(null, pc, Mailbox.ID_FOLDER_CONTACTS, new String[] { "bar" }).getId();
    int tagId = mbox.createTag(null, "foo", new Color((byte) 4)).getId();
    Element request = new Element.XMLElement(MailConstants.SYNC_REQUEST);
    Map<String, Object> context = new HashMap<String, Object>();
    context.put(SoapEngine.ZIMBRA_CONTEXT, new ZimbraSoapContext(AuthProvider.getAuthToken(acct), acct.getId(), SoapProtocol.Soap12, SoapProtocol.Soap12));
    Element response = new Sync().handle(request, context);
    String token = response.getAttribute(MailConstants.A_TOKEN);
    // check that only the explicitly-created tag is returned in the sync response
    Element tagFolder = null;
    for (Element hidden : response.getElement(MailConstants.E_FOLDER).listElements(MailConstants.E_FOLDER)) {
        if (hidden.getAttribute(MailConstants.A_NAME).equals("Tags")) {
            tagFolder = hidden;
            break;
        }
    }
    Assert.assertNotNull("could not find Tags folder in initial sync response", tagFolder);
    Assert.assertEquals("1 tag listed", 1, tagFolder.listElements(MailConstants.E_TAG).size());
    Element t = tagFolder.listElements(MailConstants.E_TAG).get(0);
    Assert.assertEquals("listed tag named 'foo'", "foo", t.getAttribute(MailConstants.A_NAME));
    Assert.assertEquals("correct color for tag 'foo'", 4, t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR));
    // change tag color and re-sync
    mbox.setColor(null, tagId, MailItem.Type.TAG, (byte) 6);
    //        mbox.purge(MailItem.Type.TAG);
    request = new Element.XMLElement(MailConstants.SYNC_REQUEST).addAttribute(MailConstants.A_TOKEN, token);
    response = new Sync().handle(request, context);
    Assert.assertFalse("sync token change after tag color", token.equals(response.getAttribute(MailConstants.A_TOKEN)));
    token = response.getAttribute(MailConstants.A_TOKEN);
    // make sure the modified tag is returned in the sync response
    t = response.getOptionalElement(MailConstants.E_TAG);
    Assert.assertNotNull("modified tag missing", t);
    Assert.assertEquals("new color on serialized tag", 6, t.getAttributeLong(MailConstants.A_COLOR, MailItem.DEFAULT_COLOR));
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Color(com.zimbra.common.mailbox.Color) Element(com.zimbra.common.soap.Element) ParsedContact(com.zimbra.cs.mime.ParsedContact) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest)

Example 13 with ParsedContact

use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.

the class Contact method generateIndexData.

@Override
public List<IndexDocument> generateIndexData() throws TemporaryIndexingException {
    mMailbox.lock.lock();
    try {
        ParsedContact pc = new ParsedContact(this);
        pc.analyze(mMailbox);
        if (pc.hasTemporaryAnalysisFailure()) {
            throw new TemporaryIndexingException();
        }
        return pc.getLuceneDocuments(mMailbox);
    } catch (ServiceException e) {
        ZimbraLog.index.error("Failed to index contact id=%d", getId());
        return Collections.emptyList();
    } finally {
        mMailbox.lock.release();
    }
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) ServiceException(com.zimbra.common.service.ServiceException)

Example 14 with ParsedContact

use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.

the class Contact method reanalyze.

@Override
void reanalyze(Object data, long newSize) throws ServiceException {
    if (!(data instanceof ParsedContact)) {
        throw ServiceException.FAILURE("cannot reanalyze non-ParsedContact object", null);
    }
    ParsedContact pc = (ParsedContact) data;
    markItemModified(Change.CONTENT | Change.DATE | Change.FLAGS);
    fields = pc.getFields();
    if (fields == null || fields.isEmpty()) {
        throw ServiceException.INVALID_REQUEST("contact must have fields", null);
    }
    attachments = pc.getAttachments();
    if (attachments != null && attachments.size() > 0) {
        for (Attachment attach : attachments) {
            //refresh the data handler. the content rev changes which can change the blob filename/locator.
            //not safe to keep old data handler that may point to old blob
            attach.mDataHandler = new DataHandler(new AttachmentDataSource(this, attach.mPartName));
        }
    }
    mData.unsetFlag(Flag.FlagInfo.ATTACHED);
    if (pc.hasAttachment()) {
        mData.setFlag(Flag.FlagInfo.ATTACHED);
    }
    saveData(new DbMailItem(mMailbox).setSender(getFileAsString(fields)));
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) DbMailItem(com.zimbra.cs.db.DbMailItem) DataHandler(javax.activation.DataHandler)

Example 15 with ParsedContact

use of com.zimbra.cs.mime.ParsedContact in project zm-mailbox by Zimbra.

the class ImportContacts method ImportCsvContacts.

public static List<ItemId> ImportCsvContacts(OperationContext oc, Mailbox mbox, ItemId iidFolder, List<Map<String, String>> csvContacts) throws ServiceException {
    List<ItemId> createdIds = new LinkedList<ItemId>();
    for (Map<String, String> contact : csvContacts) {
        String[] tags = TagUtil.decodeTags(ContactCSV.getTags(contact));
        Contact c = mbox.createContact(oc, new ParsedContact(contact), iidFolder.getId(), tags);
        createdIds.add(new ItemId(c));
        ContactGroup.MigrateContactGroup mcg = new ContactGroup.MigrateContactGroup(mbox);
        mcg.migrate(c);
    }
    return createdIds;
}
Also used : ParsedContact(com.zimbra.cs.mime.ParsedContact) ContactGroup(com.zimbra.cs.mailbox.ContactGroup) ItemId(com.zimbra.cs.service.util.ItemId) LinkedList(java.util.LinkedList) ImportContact(com.zimbra.soap.mail.type.ImportContact) Contact(com.zimbra.cs.mailbox.Contact) ParsedContact(com.zimbra.cs.mime.ParsedContact)

Aggregations

ParsedContact (com.zimbra.cs.mime.ParsedContact)41 Test (org.junit.Test)24 HashMap (java.util.HashMap)23 Mailbox (com.zimbra.cs.mailbox.Mailbox)15 Contact (com.zimbra.cs.mailbox.Contact)12 OperationContext (com.zimbra.cs.mailbox.OperationContext)12 ItemId (com.zimbra.cs.service.util.ItemId)7 ServiceException (com.zimbra.common.service.ServiceException)6 Element (com.zimbra.common.soap.Element)6 ArrayList (java.util.ArrayList)6 Account (com.zimbra.cs.account.Account)5 Attachment (com.zimbra.cs.mailbox.Contact.Attachment)5 IOException (java.io.IOException)5 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 InputStream (java.io.InputStream)4 ContactGroup (com.zimbra.cs.mailbox.ContactGroup)3 Member (com.zimbra.cs.mailbox.ContactGroup.Member)3 CreateContact (com.zimbra.cs.redolog.op.CreateContact)3 ModifyContact (com.zimbra.cs.redolog.op.ModifyContact)3 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)3