use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class DataSourceManagerTest method testGetDataImportClass.
@Test
public void testGetDataImportClass() throws ServiceException {
Map<String, Object> testAttrs = new HashMap<String, Object>();
testAttrs.put(Provisioning.A_zimbraDataSourceDomain, "zimbra.com");
testAttrs.put(Provisioning.A_zimbraDataSourceImportClassName, "com.zimbra.cs.datasource.DataSourceManagerTest.TestDSImport");
DataSource ds = new DataSource(testAccount, DataSourceType.unknown, OAUTH_DS_NAME, OAUTH_DS_ID, testAttrs, null);
assertNotNull("DataSource should not be NULL", ds);
DataImport di = DataSourceManager.getInstance().getDataImport(ds);
assertNull("should not be able to instantiate non existent DataImport class", di);
testAttrs.put(Provisioning.A_zimbraDataSourceImportClassName, "com.zimbra.cs.gal.GalImport");
ds = new DataSource(testAccount, DataSourceType.unknown, OAUTH_DS_NAME, OAUTH_DS_ID, testAttrs, null);
assertNotNull("DataSource should not be NULL", ds);
di = DataSourceManager.getInstance().getDataImport(ds);
assertNotNull("DataImport should not be NULL", di);
assertTrue("DataImport for 'unknown' should be GalImport", di instanceof GalImport);
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class DataSourceManager method getImportStatus.
public static List<ImportStatus> getImportStatus(Account account) throws ServiceException {
List<DataSource> dsList = Provisioning.getInstance().getAllDataSources(account);
List<ImportStatus> allStatus = new ArrayList<ImportStatus>();
for (DataSource ds : dsList) {
allStatus.add(getImportStatus(account, ds));
}
return allStatus;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class DataSourceTask method call.
@Override
public Void call() {
ZimbraLog.clearContext();
ZimbraLog.addMboxToContext(getMailboxId());
ZimbraLog.datasource.debug("Running scheduled import for DataSource %s", getDataSourceId());
Mailbox mbox = null;
try {
// Look up mailbox, account and data source
mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
Account account = mbox.getAccount();
ZimbraLog.addAccountNameToContext(account.getName());
Provisioning prov = Provisioning.getInstance();
DataSource ds = prov.get(account, Key.DataSourceBy.id, getDataSourceId());
if (ds != null) {
ZimbraLog.addDataSourceNameToContext(ds.getName());
if (!ds.isEnabled()) {
ZimbraLog.datasource.info("DataSource is disabled. Cancelling future tasks.");
DataSourceManager.cancelTask(mbox, getDataSourceId());
return null;
}
// Do the work
DataSourceManager.importData(ds);
} else {
ZimbraLog.datasource.info("DataSource %s was deleted. Cancelling future tasks.", getDataSourceId());
DataSourceManager.cancelTask(mbox, getDataSourceId());
}
} catch (ServiceException e) {
ZimbraLog.datasource.warn("Scheduled DataSource import failed.", e);
return null;
}
ZimbraLog.clearContext();
return null;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class CalDavDataImport method pushDelete.
private boolean pushDelete(Collection<Integer> itemIds) throws ServiceException {
DataSource ds = getDataSource();
boolean deleted = false;
ArrayList<Integer> toDelete = new ArrayList<Integer>();
for (int itemId : itemIds) {
try {
deleteRemoteItem(DbDataSource.getMapping(ds, itemId));
toDelete.add(itemId);
} catch (Exception e) {
ZimbraLog.datasource.warn("pushDelete: can't delete remote item for item " + itemId, e);
}
}
if (toDelete.size() > 0) {
DbDataSource.deleteMappings(ds, toDelete);
deleted = true;
}
return deleted;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class CalDavDataImport method getDefaultPrincipalUrl.
protected String getDefaultPrincipalUrl() {
DataSource ds = getDataSource();
String[] attrs = ds.getMultiAttr(Provisioning.A_zimbraDataSourceAttribute);
for (String a : attrs) {
if (a.startsWith("p:")) {
return a.substring(2).replaceAll("_USERNAME_", getUsername());
}
}
return null;
}
Aggregations