Search in sources :

Example 6 with DataSource

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

the class DataSourceManagerTest method testGetDataImportClass.

@Test
public void testGetDataImportClass() throws ServiceException {
    Map<String, Object> testAttrs = new HashMap<String, Object>();
    testAttrs.put(Provisioning.A_zimbraDataSourceDomain, "zimbra.com");
    testAttrs.put(Provisioning.A_zimbraDataSourceImportClassName, "com.zimbra.cs.datasource.DataSourceManagerTest.TestDSImport");
    DataSource ds = new DataSource(testAccount, DataSourceType.unknown, OAUTH_DS_NAME, OAUTH_DS_ID, testAttrs, null);
    assertNotNull("DataSource should not be NULL", ds);
    DataImport di = DataSourceManager.getInstance().getDataImport(ds);
    assertNull("should not be able to instantiate non existent DataImport class", di);
    testAttrs.put(Provisioning.A_zimbraDataSourceImportClassName, "com.zimbra.cs.gal.GalImport");
    ds = new DataSource(testAccount, DataSourceType.unknown, OAUTH_DS_NAME, OAUTH_DS_ID, testAttrs, null);
    assertNotNull("DataSource should not be NULL", ds);
    di = DataSourceManager.getInstance().getDataImport(ds);
    assertNotNull("DataImport should not be NULL", di);
    assertTrue("DataImport for 'unknown' should be GalImport", di instanceof GalImport);
}
Also used : GalImport(com.zimbra.cs.gal.GalImport) DataImport(com.zimbra.cs.account.DataSource.DataImport) HashMap(java.util.HashMap) DataSource(com.zimbra.cs.account.DataSource) Test(org.junit.Test)

Example 7 with DataSource

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

the class DataSourceManager method getImportStatus.

public static List<ImportStatus> getImportStatus(Account account) throws ServiceException {
    List<DataSource> dsList = Provisioning.getInstance().getAllDataSources(account);
    List<ImportStatus> allStatus = new ArrayList<ImportStatus>();
    for (DataSource ds : dsList) {
        allStatus.add(getImportStatus(account, ds));
    }
    return allStatus;
}
Also used : ArrayList(java.util.ArrayList) DataSource(com.zimbra.cs.account.DataSource)

Example 8 with DataSource

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

the class DataSourceTask method call.

@Override
public Void call() {
    ZimbraLog.clearContext();
    ZimbraLog.addMboxToContext(getMailboxId());
    ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", getDataSourceId());
    Mailbox mbox = null;
    try {
        // Look up mailbox, account and data source
        mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
        Account account = mbox.getAccount();
        ZimbraLog.addAccountNameToContext(account.getName());
        Provisioning prov = Provisioning.getInstance();
        DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId());
        if (ds != null) {
            ZimbraLog.addDataSourceNameToContext(ds.getName());
            if (!ds.isEnabled()) {
                ZimbraLog.datasource.info("DataSource is disabled.  Cancelling future tasks.");
                DataSourceManager.cancelTask(mbox, getDataSourceId());
                return null;
            }
            // Do the work
            DataSourceManager.importData(ds);
        } else {
            ZimbraLog.datasource.info("DataSource %s was deleted.  Cancelling future tasks.", getDataSourceId());
            DataSourceManager.cancelTask(mbox, getDataSourceId());
        }
    } catch (ServiceException e) {
        ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e);
        return null;
    }
    ZimbraLog.clearContext();
    return null;
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Example 9 with DataSource

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

the class CalDavDataImport method pushDelete.

private boolean pushDelete(Collection<Integer> itemIds) throws ServiceException {
    DataSource ds = getDataSource();
    boolean deleted = false;
    ArrayList<Integer> toDelete = new ArrayList<Integer>();
    for (int itemId : itemIds) {
        try {
            deleteRemoteItem(DbDataSource.getMapping(ds, itemId));
            toDelete.add(itemId);
        } catch (Exception e) {
            ZimbraLog.datasource.warn("pushDelete: can't delete remote item for item " + itemId, e);
        }
    }
    if (toDelete.size() > 0) {
        DbDataSource.deleteMappings(ds, toDelete);
        deleted = true;
    }
    return deleted;
}
Also used : ArrayList(java.util.ArrayList) ServiceException(com.zimbra.common.service.ServiceException) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) IOException(java.io.IOException) HttpException(org.apache.http.HttpException) DavException(com.zimbra.cs.dav.DavException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Example 10 with DataSource

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

the class CalDavDataImport method getDefaultPrincipalUrl.

protected String getDefaultPrincipalUrl() {
    DataSource ds = getDataSource();
    String[] attrs = ds.getMultiAttr(Provisioning.A_zimbraDataSourceAttribute);
    for (String a : attrs) {
        if (a.startsWith("p:")) {
            return a.substring(2).replaceAll("_USERNAME_", getUsername());
        }
    }
    return null;
}
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