use of com.zimbra.soap.admin.type.DataSourceType in project zm-mailbox by Zimbra.
the class Mailbox method updateRssDataSource.
/**
* Updates the data source for an RSS folder. If the folder URL is set,
* checks or creates a data source that updates the folder. If the URL
* is not set, deletes the data source if necessary.
*/
protected void updateRssDataSource(Folder folder) {
try {
Provisioning prov = Provisioning.getInstance();
Account account = getAccount();
DataSource ds = null;
List<DataSource> dataSources = prov.getAllDataSources(account);
for (DataSource i : dataSources) {
if (i.getFolderId() == folder.getId() && (i.getType() == DataSourceType.rss || i.getType() == DataSourceType.cal)) {
ds = i;
break;
}
}
if (StringUtil.isNullOrEmpty(folder.getUrl())) {
if (ds != null) {
// URL removed from folder.
String dsid = ds.getId();
prov.deleteDataSource(account, dsid);
DataSourceManager.cancelSchedule(account, dsid);
}
return;
}
// URL is not null or empty. Create data source if necessary.
if (ds == null) {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapConstants.LDAP_TRUE);
attrs.put(Provisioning.A_zimbraDataSourceFolderId, Integer.toString(folder.getId()));
DataSourceType type;
String name;
if (folder.getDefaultView() == MailItem.Type.APPOINTMENT) {
type = DataSourceType.cal;
name = "CAL-" + folder.getId();
} else {
type = DataSourceType.rss;
name = "RSS-" + folder.getId();
}
ds = prov.createDataSource(account, type, name, attrs);
DataSourceManager.updateSchedule(account, ds);
}
} catch (ServiceException e) {
ZimbraLog.mailbox.warn("Unable to update data source for folder %s.", folder.getPath(), e);
}
}
use of com.zimbra.soap.admin.type.DataSourceType in project zm-mailbox by Zimbra.
the class DeleteDataSource method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Mailbox mbox = getRequestedMailbox(zsc);
for (Element eDsrc : request.listElements()) {
DataSource dsrc = null;
String name, id = eDsrc.getAttribute(MailConstants.A_ID, null);
if (id != null)
dsrc = prov.get(account, Key.DataSourceBy.id, id);
else if ((name = eDsrc.getAttribute(MailConstants.A_NAME, null)) != null)
dsrc = prov.get(account, Key.DataSourceBy.name, name);
else
throw ServiceException.INVALID_REQUEST("must specify either 'id' or 'name'", null);
// note that we're not checking the element name against the actual data source's type
if (dsrc == null)
continue;
String dataSourceId = dsrc.getId();
DataSourceType dstype = dsrc.getType();
prov.deleteDataSource(account, dataSourceId);
DbDataSource.deletePurgedDataForDataSource(mbox, dataSourceId);
if (dstype == DataSourceType.pop3)
DbPop3Message.deleteUids(mbox, dataSourceId);
else if (dstype == DataSourceType.imap) {
DbImapFolder.deleteImapData(mbox, dataSourceId);
DataSourceListner.deleteDataSource(account, dsrc);
}
DbDataSource.deleteAllMappings(dsrc);
DataSourceManager.cancelSchedule(account, dataSourceId);
}
Element response = zsc.createElement(MailConstants.DELETE_DATA_SOURCE_RESPONSE);
return response;
}
use of com.zimbra.soap.admin.type.DataSourceType in project zm-mailbox by Zimbra.
the class CreateDataSource method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
String id = request.getAttribute(AdminConstants.E_ID);
Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
if (account == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(id);
checkAdminLoginAsRight(zsc, prov, account);
Element dsEl = request.getElement(AccountConstants.E_DATA_SOURCE);
Map<String, Object> attrs = AdminService.getAttrs(dsEl);
DataSourceType type = DataSourceType.fromString(dsEl.getAttribute(AccountConstants.A_TYPE));
// Note: isDomainAdminOnly *always* returns false for pure ACL based AccessManager
if (isDomainAdminOnly(zsc)) {
// yuck, can't really integrate into AdminDocumentHandler methods cleanly
// have to check separately here
AttributeClass klass = ModifyDataSource.getAttributeClassFromType(type);
checkModifyAttrs(zsc, klass, attrs);
}
String name = dsEl.getAttribute(AccountConstants.A_NAME);
DataSource ds = Provisioning.getInstance().createDataSource(account, type, name, attrs);
Element response = zsc.createElement(AdminConstants.CREATE_DATA_SOURCE_RESPONSE);
com.zimbra.cs.service.account.ToXML.encodeDataSource(response, ds);
return response;
}
use of com.zimbra.soap.admin.type.DataSourceType in project zm-mailbox by Zimbra.
the class CreateDataSource method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Element eDataSource = getDataSourceElement(request);
DataSourceType type = DataSourceType.fromString(eDataSource.getName());
boolean isAppProvisioned = doZMGAppProvisioningIfReq(zsc, prov, eDataSource, type);
Account account = getRequestedAccount(zsc);
if (eDataSource.getAttributeBool(MailConstants.A_DS_TEST, false) && !isAppProvisioned) {
TestDataSource.testDataSourceConnection(prov, eDataSource, type, account);
}
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Mailbox mbox = getRequestedMailbox(zsc);
// Create the data source
String folderIdStr = eDataSource.getAttribute(MailConstants.A_FOLDER);
int folderId = Integer.valueOf(folderIdStr);
String name = eDataSource.getAttribute(MailConstants.A_NAME);
boolean returnFolderId = false;
if (folderId == -1) {
folderId = mbox.createFolder(null, "/" + getUniqueDSFolderName(mbox, name), new Folder.FolderOptions()).getId();
folderIdStr = String.valueOf(folderId);
returnFolderId = true;
} else {
validateFolderId(account, mbox, eDataSource, type);
}
Map<String, Object> dsAttrs = new HashMap<>();
// Common attributes
dsAttrs.put(Provisioning.A_zimbraDataSourceFolderId, folderIdStr);
dsAttrs.put(Provisioning.A_zimbraDataSourceEnabled, LdapUtil.getLdapBooleanString(eDataSource.getAttributeBool(MailConstants.A_DS_IS_ENABLED)));
dsAttrs.put(Provisioning.A_zimbraDataSourceImportOnly, LdapUtil.getLdapBooleanString(eDataSource.getAttributeBool(MailConstants.A_DS_IS_IMPORTONLY, false)));
dsAttrs.put(Provisioning.A_zimbraDataSourceHost, eDataSource.getAttribute(MailConstants.A_DS_HOST));
dsAttrs.put(Provisioning.A_zimbraDataSourcePort, eDataSource.getAttribute(MailConstants.A_DS_PORT));
dsAttrs.put(Provisioning.A_zimbraDataSourceConnectionType, eDataSource.getAttribute(MailConstants.A_DS_CONNECTION_TYPE));
dsAttrs.put(Provisioning.A_zimbraDataSourceUsername, eDataSource.getAttribute(MailConstants.A_DS_USERNAME));
String value = eDataSource.getAttribute(MailConstants.A_DS_PASSWORD, null);
if (value != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourcePassword, value);
}
// type
dsAttrs.put(Provisioning.A_zimbraDataSourceType, type.toString());
// import class
String importClass = eDataSource.getAttribute(MailConstants.A_DS_IMPORT_CLASS, DataSourceManager.getDefaultImportClass(type));
if (importClass != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourceImportClassName, importClass);
}
// SMTP attributes
processSmtpAttrs(dsAttrs, eDataSource, false, null);
// Common optional attributes
ModifyDataSource.processCommonOptionalAttrs(dsAttrs, eDataSource);
// POP3-specific attributes
if (type == DataSourceType.pop3) {
dsAttrs.put(Provisioning.A_zimbraDataSourceLeaveOnServer, LdapUtil.getLdapBooleanString(eDataSource.getAttributeBool(MailConstants.A_DS_LEAVE_ON_SERVER, true)));
}
value = eDataSource.getAttribute(MailConstants.A_DS_OAUTH_TOKEN, null);
if (value != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthToken, value);
dsAttrs.put(Provisioning.A_zimbraDataSourceAuthMechanism, DataSourceAuthMechanism.XOAUTH2.name());
}
value = eDataSource.getAttribute(MailConstants.A_DS_CLIENT_ID, null);
if (value != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthClientId, value);
}
value = eDataSource.getAttribute(MailConstants.A_DS_CLIENT_SECRET, null);
if (value != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthClientSecret, value);
}
value = eDataSource.getAttribute(MailConstants.A_DS_REFRESH_TOKEN, null);
if (value != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthRefreshToken, value);
}
value = eDataSource.getAttribute(MailConstants.A_DS_REFRESH_TOKEN_URL, null);
if (value != null) {
dsAttrs.put(Provisioning.A_zimbraDataSourceOAuthRefreshTokenUrl, value);
}
DataSource ds;
try {
ds = prov.createDataSource(account, type, name, dsAttrs);
if (type == DataSourceType.imap) {
DataSourceListner.createDataSource(account, ds);
}
} catch (ServiceException e) {
if (returnFolderId) {
// we should delete the auto-created folder
mbox.delete(null, folderId, MailItem.Type.FOLDER);
}
throw e;
}
ZimbraLog.addDataSourceNameToContext(ds.getName());
// Assemble response
Element response = zsc.createElement(MailConstants.CREATE_DATA_SOURCE_RESPONSE);
eDataSource = response.addElement(type.toString());
eDataSource.addAttribute(MailConstants.A_ID, ds.getId());
if (returnFolderId) {
eDataSource.addAttribute(MailConstants.A_FOLDER, folderId);
}
return response;
}
use of com.zimbra.soap.admin.type.DataSourceType in project zm-mailbox by Zimbra.
the class TestDataSource method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
// Parse request
Element eDataSource = CreateDataSource.getDataSourceElement(request);
DataSourceType type = DataSourceType.fromString(eDataSource.getName());
String error = testDataSource(prov, account, eDataSource, type);
Element response = zsc.createElement(MailConstants.TEST_DATA_SOURCE_RESPONSE);
eDataSource = response.addElement(type.toString());
if (error == null) {
eDataSource.addAttribute(MailConstants.A_DS_SUCCESS, true);
} else {
eDataSource.addAttribute(MailConstants.A_DS_SUCCESS, false);
eDataSource.addAttribute(MailConstants.A_DS_ERROR, error);
}
return response;
}
Aggregations