Search in sources :

Example 61 with DataSource

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

the class GalSearchControl method generateLocalResourceSearchQuery.

private boolean generateLocalResourceSearchQuery(Account galAcct) throws ServiceException {
    String query = mParams.getQuery();
    StringBuilder searchQuery = new StringBuilder();
    if (!Strings.isNullOrEmpty(query)) {
        searchQuery.append("contact:\"");
        // escape quotes
        searchQuery.append(query.replace("\"", "\\\""));
        searchQuery.append("\" AND");
    }
    searchQuery.append(" #zimbraAccountCalendarUserType:RESOURCE");
    for (DataSource ds : galAcct.getAllDataSources()) {
        if (ds.getType() != DataSourceType.gal)
            continue;
        String galType = ds.getAttr(Provisioning.A_zimbraGalType);
        if (galType.compareTo("ldap") == 0)
            continue;
        searchQuery.append(" AND (");
        searchQuery.append(" inid:").append(ds.getFolderId());
        searchQuery.append(")");
        ZimbraLog.gal.debug("query: " + searchQuery.toString());
        mParams.parseSearchParams(mParams.getRequest(), searchQuery.toString());
        return true;
    }
    return false;
}
Also used : DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Example 62 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 63 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)

Example 64 with DataSource

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

the class DataSourceCallback method scheduleAccount.

private void scheduleAccount(Account account) throws ServiceException {
    ZimbraLog.datasource.info("Updating schedule for all DataSources for account %s.", account.getName());
    List<DataSource> dataSources = Provisioning.getInstance().getAllDataSources(account);
    for (DataSource ds : dataSources) {
        DataSourceManager.updateSchedule(account, ds);
    }
}
Also used : DataSource(com.zimbra.cs.account.DataSource)

Example 65 with DataSource

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

the class CreateDataSource method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    String id = request.getAttribute(AdminConstants.E_ID);
    Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    if (account == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(id);
    checkAdminLoginAsRight(zsc, prov, account);
    Element dsEl = request.getElement(AccountConstants.E_DATA_SOURCE);
    Map<String, Object> attrs = AdminService.getAttrs(dsEl);
    DataSourceType type = DataSourceType.fromString(dsEl.getAttribute(AccountConstants.A_TYPE));
    // Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager 
    if (isDomainAdminOnly(zsc)) {
        // yuck, can't really integrate into AdminDocumentHandler methods cleanly
        // have to check separately here
        AttributeClass klass = ModifyDataSource.getAttributeClassFromType(type);
        checkModifyAttrs(zsc, klass, attrs);
    }
    String name = dsEl.getAttribute(AccountConstants.A_NAME);
    DataSource ds = Provisioning.getInstance().createDataSource(account, type, name, attrs);
    Element response = zsc.createElement(AdminConstants.CREATE_DATA_SOURCE_RESPONSE);
    com.zimbra.cs.service.account.ToXML.encodeDataSource(response, ds);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) DataSourceType(com.zimbra.soap.admin.type.DataSourceType) AttributeClass(com.zimbra.cs.account.AttributeClass) Provisioning(com.zimbra.cs.account.Provisioning) 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