Search in sources :

Example 56 with DataSource

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

the class AccountUtil method getImapPop3EmailAddresses.

/**
     * Gets all email addresses for the imap and pop3 external accounts for the given account.
     * @param acct
     * @return
     * @throws ServiceException
     */
public static Set<String> getImapPop3EmailAddresses(Account acct) throws ServiceException {
    List<DataSource> dataSources = acct.getAllDataSources();
    Set<String> addrs = new HashSet<String>();
    for (DataSource dataSource : dataSources) {
        DataSourceType dataSourceType = dataSource.getType();
        if (dataSourceType == DataSourceType.imap || dataSourceType == DataSourceType.pop3) {
            addrs.add(dataSource.getEmailAddress().toLowerCase());
        }
    }
    return addrs;
}
Also used : DataSourceType(com.zimbra.soap.admin.type.DataSourceType) DataSource(com.zimbra.cs.account.DataSource) HashSet(java.util.HashSet)

Example 57 with DataSource

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

the class TestLdapProvDataSource method modifyDataSource.

@Test
public void modifyDataSource() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
    Map<String, Object> attrs = new HashMap<String, Object>();
    String MODIFIED_ATTR_NAME = Provisioning.A_zimbraDataSourceHost;
    String MODIFIED_ATTR_VALUE = "modifyDataSource.com";
    attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
    prov.modifyDataSource(acct, dataSource.getId(), attrs);
    acct = getFresh(acct);
    dataSource = prov.get(acct, Key.DataSourceBy.name, DATA_SOURCE_NAME);
    assertEquals(MODIFIED_ATTR_VALUE, dataSource.getAttr(MODIFIED_ATTR_NAME));
    deleteDataSource(acct, dataSource);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) DataSource(com.zimbra.cs.account.DataSource)

Example 58 with DataSource

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

the class TestLdapProvDataSource method getAllDataSources.

@Test
public void getAllDataSources() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String DATA_SOURCE_NAME_1 = Names.makeDataSourceName(genDataSourceName("1"));
    String DATA_SOURCE_NAME_2 = Names.makeDataSourceName(genDataSourceName("2"));
    String DATA_SOURCE_NAME_3 = Names.makeDataSourceName(genDataSourceName("3"));
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    DataSource dataSource1 = createDataSource(acct, DATA_SOURCE_NAME_1);
    DataSource dataSource2 = createDataSource(acct, DATA_SOURCE_NAME_2);
    DataSource dataSource3 = createDataSource(acct, DATA_SOURCE_NAME_3);
    acct = getFresh(acct);
    List<DataSource> allDataSources = prov.getAllDataSources(acct);
    assertEquals(3, allDataSources.size());
    Set<String> allDataSourceIds = new HashSet<String>();
    for (DataSource dataSource : allDataSources) {
        allDataSourceIds.add(dataSource.getId());
    }
    assertTrue(allDataSourceIds.contains(dataSource1.getId()));
    assertTrue(allDataSourceIds.contains(dataSource2.getId()));
    assertTrue(allDataSourceIds.contains(dataSource3.getId()));
    deleteDataSource(acct, dataSource1);
    deleteDataSource(acct, dataSource2);
    deleteDataSource(acct, dataSource3);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) DataSource(com.zimbra.cs.account.DataSource) HashSet(java.util.HashSet)

Example 59 with DataSource

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

the class TestLdapProvDataSource method getDataSource.

@Test
public void getDataSource() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
    String dataSourceId = dataSource.getId();
    acct = getFresh(acct);
    dataSource = prov.get(acct, Key.DataSourceBy.id, dataSourceId);
    assertNotNull(dataSource);
    acct = getFresh(acct);
    dataSource = prov.get(acct, Key.DataSourceBy.name, DATA_SOURCE_NAME);
    assertNotNull(dataSource);
    deleteDataSource(acct, dataSource);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) DataSource(com.zimbra.cs.account.DataSource)

Example 60 with DataSource

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

the class TestLdapProvDataSource method renameDataSource.

@Test
public void renameDataSource() throws Exception {
    String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
    String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
    Account acct = createAccount(ACCT_NAME_LOCALPART);
    DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
    Map<String, Object> attrs = new HashMap<String, Object>();
    // modifying zimbraDataSourceName will rename the data source and trigger a LDAP moddn
    String MODIFIED_ATTR_NAME = Provisioning.A_zimbraDataSourceName;
    String NEW_DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName("new"));
    String MODIFIED_ATTR_VALUE = NEW_DATA_SOURCE_NAME;
    attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
    prov.modifyDataSource(acct, dataSource.getId(), attrs);
    acct = getFresh(acct);
    dataSource = prov.get(acct, Key.DataSourceBy.name, NEW_DATA_SOURCE_NAME);
    assertEquals(MODIFIED_ATTR_VALUE, dataSource.getAttr(MODIFIED_ATTR_NAME));
    deleteDataSource(acct, dataSource);
    deleteAccount(acct);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataSource (com.zimbra.cs.account.DataSource)68 Account (com.zimbra.cs.account.Account)29 HashMap (java.util.HashMap)19 Provisioning (com.zimbra.cs.account.Provisioning)18 DbDataSource (com.zimbra.cs.db.DbDataSource)17 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 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 Test (org.junit.Test)5