Search in sources :

Example 1 with DataImport

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

the class DataSourceManager method test.

/*
     * Tests connecting to a data source.  Do not actually create the
     * data source.
     */
public static void test(DataSource ds) throws ServiceException {
    ZimbraLog.datasource.info("Testing: %s", ds);
    try {
        DataImport di = getInstance().getDataImport(ds, true);
        di.test();
        if (ds.isSmtpEnabled()) {
            Session session = JMSession.getSession(ds);
            Transport smtp = session.getTransport();
            String emailAddress = ds.getEmailAddress();
            if (smtp instanceof SmtpTransport) {
                test((SmtpTransport) smtp, emailAddress);
            } else {
                test((SMTPTransport) smtp, emailAddress);
            }
        }
        ZimbraLog.datasource.info("Test succeeded: %s", ds);
    } catch (ServiceException x) {
        ZimbraLog.datasource.info("Test failed: %s", ds, x);
        throw x;
    } catch (Exception e) {
        ZimbraLog.datasource.info("Test failed: %s", ds, e);
        throw ServiceException.INVALID_REQUEST("Datasource test failed", e);
    }
}
Also used : DataImport(com.zimbra.cs.account.DataSource.DataImport) ServiceException(com.zimbra.common.service.ServiceException) SmtpTransport(com.zimbra.cs.mailclient.smtp.SmtpTransport) Transport(javax.mail.Transport) SmtpTransport(com.zimbra.cs.mailclient.smtp.SmtpTransport) SMTPTransport(com.sun.mail.smtp.SMTPTransport) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session)

Example 2 with DataImport

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

the class SyncGalAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    ZimbraLog.addToContext(ZimbraLog.C_ANAME, getAuthenticatedAccount(zsc).getName());
    for (Element accountEl : request.listElements(AdminConstants.E_ACCOUNT)) {
        String accountId = accountEl.getAttribute(AdminConstants.A_ID);
        Account account = prov.getAccountById(accountId);
        if (account == null) {
            throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
        }
        ZimbraLog.addToContext(ZimbraLog.C_NAME, account.getName());
        for (Element dsEl : accountEl.listElements(AdminConstants.E_DATASOURCE)) {
            String by = dsEl.getAttribute(AdminConstants.A_BY);
            String name = dsEl.getText();
            DataSource ds = by.equals("id") ? account.getDataSourceById(name) : account.getDataSourceByName(name);
            if (ds == null) {
                throw AccountServiceException.NO_SUCH_DATA_SOURCE(name);
            }
            if (!ds.getType().equals(DataSourceType.gal)) {
                continue;
            }
            boolean fullSync = dsEl.getAttributeBool(AdminConstants.A_FULLSYNC, false);
            boolean reset = dsEl.getAttributeBool(AdminConstants.A_RESET, false);
            int fid = ds.getFolderId();
            DataImport dataImport = DataSourceManager.getInstance().getDataImport(ds);
            if (dataImport instanceof GalImport) {
                ((GalImport) dataImport).importGal(fid, (reset ? reset : fullSync), reset);
            }
            //flush domain gal group cache
            Domain domain = prov.getDomain(account);
            GalGroup.flushCache(domain);
        }
    }
    return zsc.createElement(AdminConstants.SYNC_GAL_ACCOUNT_RESPONSE);
}
Also used : Account(com.zimbra.cs.account.Account) GalImport(com.zimbra.cs.gal.GalImport) DataImport(com.zimbra.cs.account.DataSource.DataImport) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataImport (com.zimbra.cs.account.DataSource.DataImport)2 SMTPTransport (com.sun.mail.smtp.SMTPTransport)1 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 DataSource (com.zimbra.cs.account.DataSource)1 Domain (com.zimbra.cs.account.Domain)1 Provisioning (com.zimbra.cs.account.Provisioning)1 GalImport (com.zimbra.cs.gal.GalImport)1 SmtpTransport (com.zimbra.cs.mailclient.smtp.SmtpTransport)1 JMSession (com.zimbra.cs.util.JMSession)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 MessagingException (javax.mail.MessagingException)1 Session (javax.mail.Session)1 Transport (javax.mail.Transport)1