use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class GalImport method importGal.
public void importGal(int fid, boolean fullSync, boolean force) throws ServiceException {
mbox.beginTrackingSync();
DataSource ds = getDataSource();
DataSourceItem folderMapping = DbDataSource.getMapping(ds, fid);
if (folderMapping.md == null) {
folderMapping.itemId = fid;
folderMapping.md = new Metadata();
folderMapping.md.put(TYPE, FOLDER);
DbDataSource.addMapping(ds, folderMapping);
}
String syncToken = fullSync ? "" : folderMapping.md.get(SYNCTOKEN, "");
HashMap<String, DataSourceItem> allMappings = new HashMap<String, DataSourceItem>();
if (fullSync || force)
for (DataSourceItem dsItem : DbDataSource.getAllMappings(ds)) if (// non-folder items
dsItem.md == null || dsItem.md.get(TYPE, null) == null)
allMappings.put(dsItem.remoteId, dsItem);
OperationContext octxt = new OperationContext(mbox);
SearchGalResult result = SearchGalResult.newSearchGalResult(new GalSearchVisitor(mbox, allMappings, fid, force));
try {
searchGal(syncToken, result, true);
} catch (Exception e) {
setStatus(false);
ZimbraLog.gal.error("Error executing gal search", e);
return;
}
folderMapping.md.put(SYNCTOKEN, result.getToken());
DbDataSource.updateMapping(ds, folderMapping);
if (allMappings.size() == 0 || !fullSync) {
setStatus(true);
return;
}
ArrayList<Integer> deleted = new ArrayList<Integer>();
int[] deletedIds = new int[allMappings.size()];
int i = 0;
for (DataSourceItem dsItem : allMappings.values()) {
deleted.add(dsItem.itemId);
deletedIds[i++] = dsItem.itemId;
}
try {
mbox.delete(octxt, deletedIds, MailItem.Type.CONTACT, null);
} catch (ServiceException e) {
ZimbraLog.gal.warn("Ignoring error deleting gal contacts", e);
}
DbDataSource.deleteMappings(getDataSource(), deleted);
mbox.index.optimize();
setStatus(true);
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class ProvUtil method doAutoCompleteGal.
private void doAutoCompleteGal(String[] args) throws ServiceException {
String domain = args[1];
String query = args[2];
int limit = 100;
Domain d = lookupDomain(domain);
GalContact.Visitor visitor = new GalContact.Visitor() {
@Override
public void visit(GalContact gc) throws ServiceException {
dumpContact(gc);
}
};
SearchGalResult result = prov.autoCompleteGal(d, query, GalSearchType.all, limit, visitor);
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class AclReports method getMatchingPrincipals.
private ArrayList<DavResource> getMatchingPrincipals(DavContext ctxt, QName prop, String match, GalSearchType type) throws DavException, ServiceException {
Provisioning prov = Provisioning.getInstance();
ArrayList<DavResource> ret = new ArrayList<DavResource>();
Account authAccount = ctxt.getAuthAccount();
if (prop.equals(DavElements.E_DISPLAYNAME)) {
if (!authAccount.isFeatureGalEnabled() || !authAccount.isFeatureGalAutoCompleteEnabled())
return ret;
SearchGalResult result = prov.searchGal(prov.getDomain(authAccount), match, type, Provisioning.GalMode.zimbra, null);
for (GalContact ct : result.getMatches()) {
String email = (String) ct.getAttrs().get(ContactConstants.A_email);
if (email != null) {
Account acct = prov.get(Key.AccountBy.name, email);
if (acct != null)
ret.add(UrlNamespace.getPrincipal(ctxt, acct));
}
}
} else if (prop.equals(DavElements.E_CALENDAR_HOME_SET)) {
int index = match.lastIndexOf('/');
if (index > 0)
match = match.substring(index + 1);
Account acct = prov.get(Key.AccountBy.name, match);
if (acct != null)
ret.add(UrlNamespace.getPrincipal(ctxt, acct));
}
return ret;
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class TestGal method tokenizeTest.
private void tokenizeTest(GalOp galOp, String tokenizeKey, String key, String[] expectedUsers) throws Exception {
Domain domain = mProv.get(Key.DomainBy.name, TOKENIZE_TEST_DOMAIN_NAME);
SearchGalResult galResult = null;
if (galOp == GalOp.GOP_AUTOCOMPLETE)
galResult = mProv.autoCompleteGal(domain, key, // Provisioning.GAL_SEARCH_TYPE.ALL,
GalSearchType.account, 10, null);
else if (galOp == GalOp.GOP_SEARCH)
galResult = mProv.searchGal(domain, key, GalSearchType.account, 0, null);
else
fail();
System.out.println("tokenizeTest: key=" + key);
assertEquals(galResult.getTokenizeKey(), tokenizeKey);
Set<String> results = new HashSet<String>();
for (GalContact gc : galResult.getMatches()) {
String r = (String) gc.getAttrs().get(ContactConstants.A_email);
System.out.println(" " + r);
results.add(r);
}
for (String mail : expectedUsers) assertTrue(results.contains(mail + "@" + TOKENIZE_TEST_DOMAIN_NAME));
List<String> expectedUsersList = Arrays.asList(expectedUsers);
for (String mail : results) assertTrue(expectedUsersList.contains((mail.split("@"))[0]));
assertEquals(expectedUsers.length, galResult.getNumMatches());
}
use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.
the class TestGal method autoCompleteGal.
private void autoCompleteGal(int numResultsExpected, int maxWanted) throws Exception {
Domain domain = mProv.get(Key.DomainBy.name, DOMAIN_NAME);
SearchGalResult galResult = mProv.autoCompleteGal(domain, QUERY, // Provisioning.GAL_SEARCH_TYPE.ALL,
GalSearchType.account, maxWanted, null);
if (numResultsExpected != galResult.getNumMatches())
dumpResult(galResult);
assertEquals(numResultsExpected, galResult.getNumMatches());
boolean expectedHasMore = numResultsExpected < NUM_ACCOUNTS;
assertEquals(expectedHasMore, galResult.getHadMore());
}
Aggregations