Search in sources :

Example 1 with GalImport

use of com.zimbra.cs.gal.GalImport 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

Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 DataSource (com.zimbra.cs.account.DataSource)1 DataImport (com.zimbra.cs.account.DataSource.DataImport)1 Domain (com.zimbra.cs.account.Domain)1 Provisioning (com.zimbra.cs.account.Provisioning)1 GalImport (com.zimbra.cs.gal.GalImport)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1