use of com.zimbra.soap.type.DataSource in project zm-mailbox by Zimbra.
the class ZMailbox method createDataSource.
/**
* Creates a data source.
*
* @return the new data source id
*/
public String createDataSource(ZDataSource source) throws ServiceException {
CreateDataSourceRequest req = new CreateDataSourceRequest();
DataSource jaxbObj = source.toJaxb();
req.setDataSource(jaxbObj);
CreateDataSourceResponse resp = (CreateDataSourceResponse) invokeJaxb(req);
return resp.getDataSource().getId();
}
use of com.zimbra.soap.type.DataSource in project zm-mailbox by Zimbra.
the class DataSourceJaxbTest method testModifyDataSourceRequest.
@Test
public void testModifyDataSourceRequest() throws JAXBException {
JAXBContext jaxb = JAXBContext.newInstance(ModifyDataSourceRequest.class);
Unmarshaller unmarshaller = jaxb.createUnmarshaller();
ModifyDataSourceRequest req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyUnknownDataSourceRequest.xml"));
DataSource ds = req.getDataSource();
assertNotNull("Generic DataSource should not be NULL", ds);
assertNotNull("Generic DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for generic DataSource", "11e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
assertEquals("wrong refresh token", "AAbbccdd1244eeffVdNHR.l0_jzuWvPNtAt0BCCcOm8w9wq1gdB", ds.getRefreshToken());
assertEquals("wrong host", "yahoo.com", ds.getHost());
assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
assertEquals("wrong polling interval", "60s", ds.getPollingInterval());
req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyImapDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("IMAP DataSource should not be NULL", ds);
assertNotNull("IMAP DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for IMAP DataSource", "71e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
assertEquals("wrong polling interval", "30m", ds.getPollingInterval());
req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyCalDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("Cal DataSource should not be NULL", ds);
assertNotNull("Cal DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for Cal DataSource", "61e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailCalDataSource", ds instanceof MailCalDataSource);
assertEquals("wrong folder ID", "333", ds.getFolderId());
req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyGalDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("GAL DataSource should not be NULL", ds);
assertNotNull("GAL DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for GAL DataSource", "51e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailGalDataSource", ds instanceof MailGalDataSource);
assertEquals("wrong polling interval", "69s", ds.getPollingInterval());
req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyPop3DataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("POP3 DataSource should not be NULL", ds);
assertNotNull("POP3 DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for POP3 DataSource", "41e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailPop3DataSource", ds instanceof MailPop3DataSource);
assertEquals("wrong polling interval", "1m", ds.getPollingInterval());
assertFalse("wrong leaveOnServer", ((MailPop3DataSource) ds).isLeaveOnServer());
req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyCaldavDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("Caldav DataSource should not be NULL", ds);
assertNotNull("Caldav DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for Caldav DataSource", "31e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailCaldavDataSource", ds instanceof MailCaldavDataSource);
assertEquals("wrong polling interval", "60s", ds.getPollingInterval());
req = (ModifyDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("ModifyRssDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("RSS DataSource should not be NULL", ds);
assertNotNull("RSS DataSource ID should not be NULL", ds.getId());
assertEquals("Wrong ID for RSS DataSource", "21e1c69c-bbb3-4f5d-8903-14ef8bdacbcc", ds.getId());
assertTrue("DataSource should be an instance of MailRssDataSource", ds instanceof MailRssDataSource);
assertEquals("wrong polling interval", "2d", ds.getPollingInterval());
assertFalse("wrong isEnabled", ds.isEnabled());
}
use of com.zimbra.soap.type.DataSource in project zm-mailbox by Zimbra.
the class ZMailbox method testDataSource.
/**
* Tests a data source.
*
* @return <tt>null</tt> on success, or the error string on failure
*/
public String testDataSource(ZDataSource source) throws ServiceException {
TestDataSourceRequest req = new TestDataSourceRequest();
DataSource jaxbObj = source.toJaxb();
req.setDataSource(jaxbObj);
TestDataSourceResponse resp = (TestDataSourceResponse) invokeJaxb(req);
List<TestDataSource> dataSources = resp.getDataSources();
int success = 0;
if (dataSources.size() > 0 && dataSources.get(0) != null) {
TestDataSource ds = dataSources.get(0);
success = ds.getSuccess();
if (success < 1) {
return ds.getError();
} else {
return null;
}
}
return null;
}
use of com.zimbra.soap.type.DataSource in project zm-mailbox by Zimbra.
the class ZMailbox method getAllDataSources.
public List<ZDataSource> getAllDataSources() throws ServiceException {
GetDataSourcesResponse res = invokeJaxb(new GetDataSourcesRequest());
List<ZDataSource> result = new ArrayList<ZDataSource>();
for (DataSource ds : res.getDataSources()) {
if (ds instanceof Pop3DataSource) {
result.add(new ZPop3DataSource((Pop3DataSource) ds));
} else if (ds instanceof ImapDataSource) {
result.add(new ZImapDataSource((ImapDataSource) ds));
} else if (ds instanceof CalDataSource) {
result.add(new ZCalDataSource((CalDataSource) ds));
} else if (ds instanceof RssDataSource) {
result.add(new ZRssDataSource((RssDataSource) ds));
} else {
result.add(new ZDataSource(ds));
}
}
return result;
}
use of com.zimbra.soap.type.DataSource in project zm-mailbox by Zimbra.
the class DataSourceJaxbTest method testCreateDataSourceRequest.
@Test
public void testCreateDataSourceRequest() throws JAXBException {
JAXBContext jaxb = JAXBContext.newInstance(CreateDataSourceRequest.class);
Unmarshaller unmarshaller = jaxb.createUnmarshaller();
CreateDataSourceRequest req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreateUnknownDataSourceRequest.xml"));
DataSource ds = req.getDataSource();
assertNotNull("Generic DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailDataSource", ds instanceof MailDataSource);
assertEquals("wrong folder ID", "257", ds.getFolderId());
assertEquals("wrong refresh token", "AAbbccdd1244eeffVdNHR.l0_jzuWvPNtAt0BCCcOm8w9wq1gdB", ds.getRefreshToken());
assertEquals("wrong host", "yahoo.com", ds.getHost());
assertEquals("wrong name", "blablah@yahoo.com", ds.getName());
assertEquals("wrong import class", "com.synacor.zimbra.OAuthDataImport", ds.getImportClass());
req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreateImapDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("IMAP DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailImapDataSource", ds instanceof MailImapDataSource);
assertEquals("wrong folder ID", "2", ds.getFolderId());
assertEquals("wrong refresh token", "AAbbccdd1244eeffVdNHR.l0_jzuWvPNtAt0BCCcOm8w9wq1gdB", ds.getRefreshToken());
assertEquals("wrong clientSecret", "test123", ((MailImapDataSource) ds).getClientSecret());
assertEquals("wrong clietnId", "someclientid", ((MailImapDataSource) ds).getClientId());
// using a string that's as long as a real OAuth2 token to make sure Jaxb does not truncate it
assertEquals("wrong oauth token", "LoremIpsumZZZyyY123.MaybeLorem.53445.WWW.YelpcYE1p6L1iS5vwZAg8pntEPGs2M.FcbPqY7PxBxORvoYhcbiTLlK7YcRwMB.1gprP5vxYghvqPT9KKV_EJ2vpDQr881.dzLB896UWZYI3hLrqAwiePEhFdw1XXTNP4u6gJ8J6ErPSZJInN1SMK74smQZErEpBgNfyFD2kgNPfcdxjMLh5ODjvhMufHcsb_NI5liTCOWa7k693ziHVZQkyGCJdAzxhtYeIyaCxyTsvaj3ybeXcye.qWFvwpdZbqWj8U8DqRXpjrq6wnNsK1ljGafon_uuX06wWNLh5P0GmLkaW4Yrumh9L7ir59Wm9bQ98TuHxNQDnLLqCK42P3Grb8guWGFRetPiLV2mb4ZT0fPAOeYPmaJXc2_OEWtr.KlazJt.ig6Me1HWR0vHC_MnfHUFA028wooDD9URrhTeMrvizeoePMfd3tgMEw721AbAoH58tg5VebNH_F_.wlQKYkU9rXv4v5Mzw3vsCKvW6wniJzepaY6gwKpMjlWn4CxAQNwRMPyoCDR2gRUXriulDO7vKbQ1ku_g2H.Swq2XGyr0EKjOjRAKVNGWJAh.1flPkzF0W5n7kcgJnG1H3AopZJMAypTiNQEDEyjqDCF41jgN4rKo5q9skZMbRG0D5jL0T_SoKDp6jWoXbWAmeog4Tb0eCHD0QJJGOa1BfFZkXbDB0Eet8JxxfG.0vM23oIervWHqcBPlfKJtkxiI9CCdqOniDNPfhbxkaSlOq3bQRmFOq08jaOwswlsECm4U95bEDxAtKcnVl8AnrP8qsbqxmanHdTh.dehEnjJ1gXyGpaMEBA2Yrt_QEewyWEDuR_zBKsomeDotsSp1.tyw3WCqnMx27tArDDasdNNlPPdfRVQlqe6gX45HfK0C8PAXsPnqZUA07.pFTa8ifcucsdqbh3_UpXnuPj8Mn.67GxwvujJkO8WpD3nCQpwp4Fns6NOnoNoasdgyiSCcGpCsGs2l6ZIFJyUMvIf4q6cfEiJ18lyBjRxi3rpgMAYTt5sOmikOst.gttN1gettkvWyY8-", ((MailImapDataSource) ds).getOAuthToken());
assertEquals("wrong host", "imap.yahoo.com", ds.getHost());
assertEquals("wrong name", "blablah2@yahoo.com", ds.getName());
req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreateCalDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("Cal DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailCalDataSource", ds instanceof MailCalDataSource);
assertEquals("wrong folder ID", "5", ds.getFolderId());
assertEquals("wrong host", "calendar.google.com", ds.getHost());
assertEquals("wrong name", "someCalDS", ds.getName());
req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreateGalDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("GAL DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailGalDataSource", ds instanceof MailGalDataSource);
assertEquals("wrong folder ID", "7", ds.getFolderId());
assertEquals("wrong host", "ldap.zimbra.com", ds.getHost());
assertEquals("wrong name", "zimbraGAL", ds.getName());
assertEquals("wrong polling interval", "24h", ds.getPollingInterval());
assertTrue("wrong isEnabled", ds.isEnabled());
req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreatePop3DataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("POP3 DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailPop3DataSource", ds instanceof MailPop3DataSource);
assertEquals("wrong folder ID", "1", ds.getFolderId());
assertEquals("wrong host", "pop.email.provider.domain", ds.getHost());
assertEquals("wrong name", "pop3DSForTest", ds.getName());
assertEquals("wrong polling interval", "24h", ds.getPollingInterval());
assertTrue("wrong leaveOnServer", ((MailPop3DataSource) ds).isLeaveOnServer());
assertFalse("wrong isEnabled", ds.isEnabled());
req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreateCaldavDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("CalDAV DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailCaldavDataSource", ds instanceof MailCaldavDataSource);
assertEquals("wrong folder ID", "3", ds.getFolderId());
assertEquals("wrong host", "some.cal.dav.host", ds.getHost());
assertEquals("wrong name", "caldavDS", ds.getName());
assertEquals("wrong polling interval", "1h", ds.getPollingInterval());
assertFalse("wrong isEnabled", ds.isEnabled());
req = (CreateDataSourceRequest) unmarshaller.unmarshal(getClass().getResourceAsStream("CreateRssDataSourceRequest.xml"));
ds = req.getDataSource();
assertNotNull("RSS DataSource should not be NULL", ds);
assertTrue("DataSource should be an instance of MailRssDataSource", ds instanceof MailRssDataSource);
assertEquals("wrong folder ID", "260", ds.getFolderId());
assertEquals("wrong host", "some.rss.dav.host", ds.getHost());
assertEquals("wrong name", "RssFeedDataSource", ds.getName());
assertEquals("wrong polling interval", "30m", ds.getPollingInterval());
assertTrue("wrong isEnabled", ds.isEnabled());
}
Aggregations