use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class ProvTestUtil method createDataSourceRaw.
public DataSource createDataSourceRaw(Account acct, String dataSourceName) throws Exception {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
attrs.put(Provisioning.A_zimbraDataSourceFolderId, "123");
attrs.put(Provisioning.A_zimbraDataSourceConnectionType, "ssl");
attrs.put(Provisioning.A_zimbraDataSourceHost, "zimbra.com");
attrs.put(Provisioning.A_zimbraDataSourcePort, "9999");
DataSource ds = prov.createDataSource(acct, DataSourceType.pop3, dataSourceName, attrs);
createdAccountSubordinates.add(ds);
return ds;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class TestPop3ImportServer method testUidPersistence.
/*
* Tests the UID persistence methods in {@link DbPop3Message}.
*/
@Test
public void testUidPersistence() throws Exception {
mIsServerSideTest = true;
DataSource ds = getDataSource();
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
// Create set of id's. Id's are the same characters in different
// case, to test case-sensitivity (bug 15090)
String uid1 = "myUID";
String uid2 = "myUid";
Set<String> uids = new HashSet<String>();
uids.add(uid1);
uids.add(uid2);
// Make sure no id's match
Set<String> matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
assertEquals("Test 1: set size", 0, matchingUids.size());
// Store uid1 and make sure it matches
DbPop3Message.storeUid(mbox, ds.getId(), uid1, Mailbox.ID_FOLDER_INBOX);
matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
assertEquals("Test 2: set size", 1, matchingUids.size());
assertTrue("Test 2: did not find uid1", matchingUids.contains(uid1));
assertFalse("Test 2: found uid2", matchingUids.contains(uid2));
// Store uid2 and make sure it matches
DbPop3Message.storeUid(mbox, ds.getId(), uid2, Mailbox.ID_FOLDER_TRASH);
matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
assertEquals("Test 3: set size", 2, matchingUids.size());
assertTrue("Test 3: did not find uid1", matchingUids.contains(uid1));
assertTrue("Test 3: did not find uid2", matchingUids.contains(uid2));
// Test delete
DbPop3Message.deleteUids(mbox, ds.getId());
matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
assertEquals("Test 3: set size", 0, matchingUids.size());
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class CreateGalSyncAccount method addDataSource.
static void addDataSource(Element request, ZimbraSoapContext zsc, Account account, Domain domain, String folder, String name, GalMode type) throws ServiceException {
String acctName = account.getName();
String acctId = account.getId();
HashSet<String> galAcctIds = new HashSet<String>();
galAcctIds.addAll(Arrays.asList(domain.getGalAccountId()));
if (!galAcctIds.contains(acctId)) {
galAcctIds.add(acctId);
domain.setGalAccountId(galAcctIds.toArray(new String[0]));
}
// create folder if not already exists.
if (folder == null) {
folder = "/Contacts";
} else if (folder.length() > 0 && folder.charAt(0) != '/') {
folder = "/" + folder;
}
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
Folder contactFolder = null;
try {
contactFolder = mbox.getFolderByPath(null, folder);
} catch (MailServiceException.NoSuchItemException e) {
contactFolder = mbox.createFolder(null, folder, new Folder.FolderOptions().setDefaultView(MailItem.Type.CONTACT));
}
int folderId = contactFolder.getId();
// check if there is another datasource already that maps to the same contact folder.
for (DataSource ds : account.getAllDataSources()) {
if (ds.getFolderId() == folderId) {
throw MailServiceException.ALREADY_EXISTS("data source " + ds.getName() + " already contains folder " + folder);
}
}
mbox.grantAccess(null, folderId, domain.getId(), ACL.GRANTEE_DOMAIN, ACL.stringToRights("r"), null);
// create datasource
Map<String, Object> attrs = AdminService.getAttrs(request, true);
try {
attrs.put(Provisioning.A_zimbraGalType, type.name());
attrs.put(Provisioning.A_zimbraDataSourceFolderId, "" + folderId);
if (!attrs.containsKey(Provisioning.A_zimbraDataSourceEnabled)) {
attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
}
if (!attrs.containsKey(Provisioning.A_zimbraGalStatus)) {
attrs.put(Provisioning.A_zimbraGalStatus, "enabled");
}
Provisioning.getInstance().createDataSource(account, DataSourceType.gal, name, attrs);
} catch (ServiceException e) {
ZimbraLog.gal.error("error creating datasource for GalSyncAccount", e);
throw e;
}
ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateGalSyncAccount", "name", acctName }));
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class GetDataSources method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetDataSourcesRequest req = zsc.elementToJaxb(request);
String id = req.getId();
Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
defendAgainstAccountOrCalendarResourceHarvesting(account, AccountBy.id, id, zsc, Admin.R_adminLoginAs, Admin.R_adminLoginCalendarResourceAs);
Element response = zsc.createElement(AdminConstants.GET_DATA_SOURCES_RESPONSE);
List<DataSource> sources = Provisioning.getInstance().getAllDataSources(account);
for (DataSource ds : sources) {
com.zimbra.cs.service.account.ToXML.encodeDataSource(response, ds);
}
return response;
}
use of com.zimbra.cs.account.DataSource 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);
}
Aggregations