Search in sources :

Example 36 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class TestDataSource method testIsScheduled.

/**
 * Tests {@link DataSource#isScheduled()}.
 */
@Test
public void testIsScheduled() throws Exception {
    // Create data source
    Provisioning prov = Provisioning.getInstance();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_FALSE);
    attrs.put(Provisioning.A_zimbraDataSourceHost, "testhost");
    attrs.put(Provisioning.A_zimbraDataSourcePort, "0");
    attrs.put(Provisioning.A_zimbraDataSourceUsername, TEST_USER_NAME);
    attrs.put(Provisioning.A_zimbraDataSourcePassword, "test123");
    attrs.put(Provisioning.A_zimbraDataSourceFolderId, "1");
    attrs.put(Provisioning.A_zimbraDataSourceConnectionType, ConnectionType.cleartext.toString());
    String name = NAME_PREFIX + " testNegativePollingInterval";
    DataSource ds = prov.createDataSource(account, DataSourceType.pop3, name, attrs);
    // Test polling interval not set.
    ds = account.getDataSourceByName(name);
    assertFalse("DataSource was scheduled when NOT expected - Missing interval", ds.isScheduled());
    // Test polling interval = 0.
    attrs.clear();
    attrs.put(Provisioning.A_zimbraDataSourcePollingInterval, "0");
    prov.modifyDataSource(account, ds.getId(), attrs);
    ds = account.getDataSourceByName(name);
    assertFalse("DataSource was scheduled when NOT expected - Interval \"0\"", ds.isScheduled());
    // Test polling interval > 0.
    attrs.clear();
    attrs.put(Provisioning.A_zimbraDataSourcePollingInterval, "365d");
    prov.modifyDataSource(account, ds.getId(), attrs);
    ds = account.getDataSourceByName(name);
    assertTrue("DataSource was NOT scheduled when expected - 365d interval", ds.isScheduled());
}
Also used : HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) ZDataSource(com.zimbra.client.ZDataSource) ZCalDataSource(com.zimbra.client.ZCalDataSource) ZRssDataSource(com.zimbra.client.ZRssDataSource) DataSource(com.zimbra.cs.account.DataSource) MailPop3DataSource(com.zimbra.soap.mail.type.MailPop3DataSource) Test(org.junit.Test)

Example 37 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class TestDataSource method testErrorStatus.

/**
 * Tests the <tt>lastError</tt> element and <tt>failingSince</tt> attribute
 * for <tt>GetInfoRequest</tt> and <tt>GetDataSourcesRequest</tt>.
 */
@Test
public void testErrorStatus() throws Exception {
    // Create data source.
    Account testAccount = TestUtil.getAccount(TEST_USER_NAME);
    Provisioning prov = Provisioning.getInstance();
    Map<String, Object> attrs = new HashMap<String, Object>();
    attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
    attrs.put(Provisioning.A_zimbraDataSourceHost, "localhost");
    attrs.put(Provisioning.A_zimbraDataSourcePort, TestUtil.getServerAttr(Provisioning.A_zimbraPop3BindPort));
    attrs.put(Provisioning.A_zimbraDataSourceUsername, USER_NAME_2);
    attrs.put(Provisioning.A_zimbraDataSourcePassword, TestUtil.DEFAULT_PASSWORD);
    attrs.put(Provisioning.A_zimbraDataSourceFolderId, Integer.toString(Mailbox.ID_FOLDER_INBOX));
    attrs.put(Provisioning.A_zimbraDataSourceConnectionType, ConnectionType.cleartext.toString());
    attrs.put(Provisioning.A_zimbraDataSourceLeaveOnServer, LdapConstants.LDAP_TRUE);
    DataSource ds = prov.createDataSource(testAccount, DataSourceType.pop3, DS_NAME, attrs);
    // Make sure error status is not set.
    ZMailbox mbox = TestUtil.getZMailbox(TEST_USER_NAME);
    confirmErrorStatus(mbox, null);
    // Invoke data source sync and make sure error status is not set.
    ZDataSource zds = TestUtil.getDataSource(mbox, DS_NAME);
    TestUtil.importDataSource(zds, mbox, null, true);
    confirmErrorStatus(mbox, null);
    // Change to an invalid password, make sure error status is set.
    attrs.clear();
    attrs.put(Provisioning.A_zimbraDataSourcePassword, "bogus");
    prov.modifyDataSource(testAccount, ds.getId(), attrs);
    Thread.sleep(500);
    zds = TestUtil.getDataSource(mbox, DS_NAME);
    // timestamp is returned in seconds, not millis
    long startTimestamp = System.currentTimeMillis() / 1000;
    TestUtil.importDataSource(zds, mbox, null, false);
    confirmErrorStatus(mbox, startTimestamp);
    // Fix password, make sure that error status is reset (bug 39050).
    attrs.put(Provisioning.A_zimbraDataSourcePassword, TestUtil.DEFAULT_PASSWORD);
    prov.modifyDataSource(testAccount, ds.getId(), attrs);
    Thread.sleep(500);
    confirmErrorStatus(mbox, null);
    // Do another sync, make sure error password is not set.
    zds = TestUtil.getDataSource(mbox, DS_NAME);
    startTimestamp = System.currentTimeMillis();
    TestUtil.importDataSource(zds, mbox, null, true);
    confirmErrorStatus(mbox, null);
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) ZDataSource(com.zimbra.client.ZDataSource) ZDataSource(com.zimbra.client.ZDataSource) ZCalDataSource(com.zimbra.client.ZCalDataSource) ZRssDataSource(com.zimbra.client.ZRssDataSource) DataSource(com.zimbra.cs.account.DataSource) MailPop3DataSource(com.zimbra.soap.mail.type.MailPop3DataSource) Test(org.junit.Test)

Example 38 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class GalSearchControl method generateSearchQuery.

private void generateSearchQuery(Account galAcct) throws ServiceException {
    String query = mParams.getQuery();
    String searchByDn = mParams.getSearchEntryByDn();
    GalSearchType type = mParams.getType();
    StringBuilder searchQuery = new StringBuilder();
    if (searchByDn != null) {
        searchQuery.append("#dn:(" + searchByDn + ")");
    } else if (!Strings.isNullOrEmpty(query)) {
        searchQuery.append("contact:\"");
        // escape quotes
        searchQuery.append(query.replace("\"", "\\\""));
        searchQuery.append("\" AND");
    }
    GalSearchQueryCallback queryCallback = mParams.getExtraQueryCallback();
    if (queryCallback != null) {
        String extraQuery = queryCallback.getMailboxSearchQuery();
        if (extraQuery != null) {
            ZimbraLog.gal.debug("extra search query: " + extraQuery);
            searchQuery.append(" (").append(extraQuery).append(") AND");
        }
    }
    GalMode galMode = mParams.getDomain().getGalMode();
    boolean first = true;
    for (DataSource ds : galAcct.getAllDataSources()) {
        if (ds.getType() != DataSourceType.gal)
            continue;
        String galType = ds.getAttr(Provisioning.A_zimbraGalType);
        if (galMode == GalMode.ldap && galType.compareTo("zimbra") == 0)
            continue;
        if (galMode == GalMode.zimbra && galType.compareTo("ldap") == 0)
            continue;
        if (first)
            searchQuery.append("(");
        else
            searchQuery.append(" OR");
        first = false;
        searchQuery.append(" inid:").append(ds.getFolderId());
    }
    if (!first)
        searchQuery.append(")");
    switch(type) {
        case resource:
            searchQuery.append(" AND #zimbraAccountCalendarUserType:RESOURCE");
            break;
        case group:
            searchQuery.append(" AND #type:group");
            break;
        case account:
            searchQuery.append(" AND !(#zimbraAccountCalendarUserType:RESOURCE)");
            break;
        case all:
            break;
    }
    ZimbraLog.gal.debug("query: %s", searchQuery);
    mParams.parseSearchParams(mParams.getRequest(), searchQuery.toString());
}
Also used : GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) GalSearchType(com.zimbra.soap.type.GalSearchType) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Example 39 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class GalSearchControl method getSearchQuery.

private String getSearchQuery(Account galAcct, boolean addInId) throws ServiceException {
    String query = mParams.getQuery();
    String searchByDn = mParams.getSearchEntryByDn();
    GalSearchType type = mParams.getType();
    StringBuilder searchQuery = new StringBuilder();
    if (searchByDn != null) {
        searchQuery.append("#dn:(" + searchByDn + ")");
    } else if (!Strings.isNullOrEmpty(query)) {
        searchQuery.append("contact:\"");
        // escape quotes
        searchQuery.append(query.replace("\"", "\\\""));
        searchQuery.append("\"");
    }
    GalSearchQueryCallback queryCallback = mParams.getExtraQueryCallback();
    if (queryCallback != null) {
        String extraQuery = queryCallback.getMailboxSearchQuery();
        if (extraQuery != null) {
            ZimbraLog.gal.debug("extra search query: " + extraQuery);
            if (!StringUtil.isNullOrEmpty(searchQuery.toString())) {
                searchQuery.append(" AND");
            }
            searchQuery.append(" (").append(extraQuery).append(")");
        }
    }
    boolean first = true;
    boolean needClosing = false;
    if (addInId && galAcct != null) {
        GalMode galMode = mParams.getDomain().getGalMode();
        for (DataSource ds : galAcct.getAllDataSources()) {
            if (ds.getType() != DataSourceType.gal)
                continue;
            String galType = ds.getAttr(Provisioning.A_zimbraGalType);
            if (galMode == GalMode.ldap && galType.compareTo("zimbra") == 0)
                continue;
            if (galMode == GalMode.zimbra && galType.compareTo("ldap") == 0)
                continue;
            if (!StringUtil.isNullOrEmpty(searchQuery.toString())) {
                if (first) {
                    searchQuery.append(" AND (");
                    needClosing = true;
                } else {
                    searchQuery.append(" OR");
                }
            }
            first = false;
            searchQuery.append(" inid:").append(ds.getFolderId());
        }
    }
    if (needClosing)
        searchQuery.append(")");
    switch(type) {
        case resource:
            searchQuery.append(" AND #zimbraAccountCalendarUserType:RESOURCE");
            break;
        case group:
            searchQuery.append(" AND #type:group");
            break;
        case account:
            searchQuery.append(" AND !(#zimbraAccountCalendarUserType:RESOURCE)");
            break;
        case all:
            break;
    }
    ZimbraLog.gal.debug("query: %s", searchQuery);
    return searchQuery.toString();
}
Also used : GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) GalSearchType(com.zimbra.soap.type.GalSearchType) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Example 40 with DataSource

use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.

the class GalImport method searchGal.

private void searchGal(String syncToken, SearchGalResult result, boolean fetchGroupMembers) throws ServiceException {
    ZimbraLog.gal.debug("searchGal: " + syncToken);
    DataSource ds = getDataSource();
    GalSearchParams params = new GalSearchParams(ds);
    params.setGalResult(result);
    params.setToken(syncToken);
    params.setQuery("*");
    for (String attr : ZIMBRA_ATTRS) params.getConfig().getRules().add(attr + "=" + attr);
    params.getConfig().getRules().setFetchGroupMembers(fetchGroupMembers);
    params.getConfig().getRules().setNeedSMIMECerts(true);
    Provisioning.getInstance().searchGal(params);
}
Also used : DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataSource (com.zimbra.cs.account.DataSource)71 Account (com.zimbra.cs.account.Account)29 HashMap (java.util.HashMap)21 Provisioning (com.zimbra.cs.account.Provisioning)18 DbDataSource (com.zimbra.cs.db.DbDataSource)18 ServiceException (com.zimbra.common.service.ServiceException)15 Element (com.zimbra.common.soap.Element)14 Mailbox (com.zimbra.cs.mailbox.Mailbox)11 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)11 ArrayList (java.util.ArrayList)11 ZDataSource (com.zimbra.client.ZDataSource)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Folder (com.zimbra.cs.mailbox.Folder)7 DataSourceType (com.zimbra.soap.admin.type.DataSourceType)7 HashSet (java.util.HashSet)7 Test (org.junit.Test)7 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)6 ZMailbox (com.zimbra.client.ZMailbox)5 LdapDataSource (com.zimbra.cs.account.ldap.entry.LdapDataSource)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5