use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class TestLdapProvAccount method renameAccount.
/*
* This test does not work with JNDI. The trailing space in data source name
* got stripped after the rename.
*/
@Test
public void renameAccount() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String ACCT_NEW_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart("new"));
String ACCT_NEW_NAME = TestUtil.getAddress(ACCT_NEW_NAME_LOCALPART, domain.getName()).toLowerCase();
Account acct = createAccount(ACCT_NAME_LOCALPART);
String acctId = acct.getId();
// create some children
String DATA_SOURCE_NAME_1;
String DATA_SOURCE_NAME_2;
String DATA_SOURCE_NAME_3;
DATA_SOURCE_NAME_1 = Names.makeDataSourceName(genDataSourceName("1"));
DATA_SOURCE_NAME_2 = Names.makeDataSourceName(genDataSourceName("2"));
DATA_SOURCE_NAME_3 = Names.makeDataSourceName(genDataSourceName("3"));
DataSource ds1 = createDataSource(acct, DATA_SOURCE_NAME_1);
DataSource ds2 = createDataSource(acct, DATA_SOURCE_NAME_2);
DataSource ds3 = createDataSource(acct, DATA_SOURCE_NAME_3);
String DATA_SOURCE_ID_1 = ds1.getId();
String DATA_SOURCE_ID_2 = ds2.getId();
String DATA_SOURCE_ID_3 = ds3.getId();
// set zimbraPrefAllowAddressForDelegatedSender
Map<String, Object> attrs = Maps.newHashMap();
attrs.put(Provisioning.A_zimbraPrefAllowAddressForDelegatedSender, acct.getName());
prov.modifyAttrs(acct, attrs);
prov.renameAccount(acctId, ACCT_NEW_NAME);
prov.flushCache(CacheEntryType.account, null);
Account renamedAcct = prov.get(AccountBy.name, ACCT_NEW_NAME);
assertEquals(acctId, renamedAcct.getId());
assertEquals(ACCT_NEW_NAME, renamedAcct.getName());
assertEquals(ACCT_NEW_NAME_LOCALPART, renamedAcct.getUid());
// make sure children are moved
assertEquals(DATA_SOURCE_ID_1, prov.get(renamedAcct, Key.DataSourceBy.name, DATA_SOURCE_NAME_1).getId());
assertEquals(DATA_SOURCE_ID_2, prov.get(renamedAcct, Key.DataSourceBy.name, DATA_SOURCE_NAME_2).getId());
assertEquals(DATA_SOURCE_ID_3, prov.get(renamedAcct, Key.DataSourceBy.name, DATA_SOURCE_NAME_3).getId());
// make sure zimbraPrefAllowAddressForDelegatedSender is updated
Set<String> addrsForDelegatedSender = renamedAcct.getMultiAttrSet(Provisioning.A_zimbraPrefAllowAddressForDelegatedSender);
assertEquals(1, addrsForDelegatedSender.size());
assertTrue(addrsForDelegatedSender.contains(ACCT_NEW_NAME));
deleteAccount(renamedAcct);
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class TestCalDavImportServer method cleanUp.
private void cleanUp() throws Exception {
// Delete data source
Account account = TestUtil.getAccount(TEMP_USER_NAME);
if (account != null) {
Provisioning prov = Provisioning.getInstance();
DataSource ds = prov.get(account, Key.DataSourceBy.name, DATA_SOURCE_NAME);
if (ds != null) {
prov.deleteDataSource(account, ds.getId());
}
TestUtil.deleteTestData(TEMP_USER_NAME, NAME_PREFIX);
TestUtil.deleteAccount(TEMP_USER_NAME);
}
account = TestUtil.getAccount(USER_NAME);
if (account != null) {
TestUtil.deleteTestData(USER_NAME, NAME_PREFIX);
TestUtil.deleteAccount(USER_NAME);
}
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class TestPop3ImportServer method modifyAndCheck.
/*
* Modifies the data source and confirms whether UID data was deleted.
*/
private void modifyAndCheck(ZPop3DataSource zds, boolean shouldDeleteData) throws Exception {
Mailbox mbox = TestUtil.getMailbox(USER_NAME);
DataSource ds = getDataSource();
ZMailbox zmbox = TestUtil.getZMailbox(USER_NAME);
// Reinitialize persisted UID's
DbPop3Message.deleteUids(mbox, ds.getId());
DbPop3Message.storeUid(mbox, ds.getId(), "1", Mailbox.ID_FOLDER_INBOX);
// Modify data source and make sure the existing
// UID's were deleted
zmbox.modifyDataSource(zds);
Set<String> uids = new HashSet<String>();
uids.add("1");
Set<String> matchingUids = DbPop3Message.getMatchingUids(mbox, ds, uids);
int expected = shouldDeleteData ? 0 : 1;
assertEquals("matching UID's: " + StringUtil.join(",", matchingUids), expected, matchingUids.size());
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class CalDavDataImport method getRemoteItems.
private List<RemoteItem> getRemoteItems(Folder folder) throws ServiceException, IOException, DavException {
ZimbraLog.datasource.debug("Refresh folder %s", folder.getPath());
DataSource ds = getDataSource();
DataSourceItem item = DbDataSource.getMapping(ds, folder.getId());
if (item.md == null)
throw ServiceException.FAILURE("Mapping for folder " + folder.getPath() + " not found", null);
// CalDAV doesn't provide delete tombstone. in order to check for deleted appointments
// we need to cross reference the current result with what we have from last sync
// and check for any appointment that has disappeared since last sync.
HashMap<String, DataSourceItem> allItems = new HashMap<String, DataSourceItem>();
for (DataSourceItem localItem : DbDataSource.getAllMappingsInFolder(getDataSource(), folder.getId())) allItems.put(localItem.remoteId, localItem);
ArrayList<RemoteItem> ret = new ArrayList<RemoteItem>();
CalDavClient client = getClient();
Collection<Appointment> appts = client.getEtags(item.remoteId);
for (Appointment a : appts) {
ret.add(new RemoteCalendarItem(a.href, a.etag));
allItems.remove(a.href);
}
ArrayList<Integer> deletedIds = new ArrayList<Integer>();
for (DataSourceItem deletedItem : allItems.values()) {
// what's left in the collection are previous mapping that has disappeared.
// we need to delete the appointments that are mapped locally.
RemoteCalendarItem rci = new RemoteCalendarItem(deletedItem.remoteId, null);
rci.status = Status.deleted;
rci.itemId = deletedItem.itemId;
ret.add(rci);
deletedIds.add(deletedItem.itemId);
ZimbraLog.datasource.debug("deleting: %d (%s) ", deletedItem.itemId, deletedItem.remoteId);
}
if (!deletedIds.isEmpty())
DbDataSource.deleteMappings(ds, deletedIds);
return ret;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class DataSourceFolderListener method notify.
@Override
public void notify(ChangeNotification notification) {
if (notification.mods.deleted != null) {
for (Map.Entry<ModificationKey, Change> entry : notification.mods.deleted.entrySet()) {
MailItem.Type type = (MailItem.Type) entry.getValue().what;
if (type == MailItem.Type.FOLDER) {
Folder oldFolder = (Folder) entry.getValue().preModifyObj;
if (oldFolder == null) {
ZimbraLog.datasource.warn("Cannot determine the old folder name for %s.", entry.getKey());
continue;
}
try {
ZimbraLog.datasource.info("Deleting datasources that reference %s.", oldFolder.getPath());
Account account = oldFolder.getAccount();
List<DataSource> datasources = account.getAllDataSources();
for (DataSource datasource : datasources) {
if (datasource.getFolderId() == oldFolder.getId()) {
ZimbraLog.datasource.debug("Deleting datasource %s.", datasource.getName());
account.deleteDataSource(datasource.getId());
}
}
} catch (ServiceException e) {
ZimbraLog.datasource.warn("Could not delete datasources for folder.", oldFolder.getPath());
}
}
}
}
}
Aggregations