use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class GetDataSourceUsage method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
GetDataSourceUsageResponse resp = new GetDataSourceUsageResponse();
resp.setDataSourceQuota(account.getDataSourceQuota());
resp.setDataSourceTotalQuota(account.getDataSourceTotalQuota());
for (DataSource ds : account.getAllDataSources()) {
DataSourceUsage dsu = new DataSourceUsage();
dsu.setId(ds.getId());
dsu.setUsage(ds.getUsage());
resp.addDataSourceUsage(dsu);
}
return zsc.jaxbToElement(resp);
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class ItemActionHelper method MOVE.
/**
* Account relative path conversation move.
*/
public static List<ItemActionHelper> MOVE(OperationContext octxt, Mailbox mbox, SoapProtocol responseProto, List<Integer> ids, TargetConstraint tcon, String acctRelativePath) throws ServiceException {
List<ItemActionHelper> returnList = new ArrayList<>();
// First build all external account / data source root folder ids
Set<Integer> dsRootFolderIds = new HashSet<>();
if (!ids.isEmpty()) {
List<DataSource> dataSources = mbox.getAccount().getAllDataSources();
if (dataSources != null) {
for (DataSource ds : dataSources) {
int dsFolderId = ds.getFolderId();
if (dsFolderId != -1) {
dsRootFolderIds.add(dsFolderId);
}
}
}
}
for (int convId : ids) {
Integer rootFolderIdForConv = null;
for (Message msg : mbox.getMessagesByConversation(octxt, convId, SortBy.NONE, -1)) {
int rootFolderIdForThisMsg = AccountUtil.getRootFolderIdForItem(msg, mbox, dsRootFolderIds);
if (rootFolderIdForConv == null) {
rootFolderIdForConv = rootFolderIdForThisMsg;
} else if (rootFolderIdForConv != rootFolderIdForThisMsg) {
// this is conv spanning multiple accounts / data sources
rootFolderIdForConv = null;
break;
}
}
if (rootFolderIdForConv == null) {
continue;
}
Folder rootFolder = mbox.getFolderById(octxt, rootFolderIdForConv);
String rootFolderPath = rootFolder.getPath();
rootFolderPath = "/".equals(rootFolderPath) ? "" : rootFolderPath;
String targetFolderPath = rootFolderPath.concat(acctRelativePath.startsWith("/") ? acctRelativePath : "/" + acctRelativePath);
Folder targetFolder;
try {
targetFolder = mbox.getFolderByPath(octxt, targetFolderPath);
} catch (MailServiceException.NoSuchItemException e) {
targetFolder = mbox.createFolder(octxt, targetFolderPath, new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
}
returnList.add(MOVE(octxt, mbox, responseProto, Arrays.asList(convId), MailItem.Type.CONVERSATION, tcon, new ItemId(targetFolder)));
}
return returnList;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class ItemAction method getDataSourceOfItem.
private String getDataSourceOfItem(OperationContext octxt, Mailbox mbox, MailItem item) throws ServiceException {
Folder folder = mbox.getFolderById(octxt, item.getFolderId());
Map<Integer, String> dataSources = new HashMap<Integer, String>();
for (DataSource ds : mbox.getAccount().getAllDataSources()) {
dataSources.put(ds.getFolderId(), ds.getId());
}
while (folder.getId() != Mailbox.ID_FOLDER_ROOT) {
if (dataSources.containsKey(folder.getId())) {
return dataSources.get(folder.getId());
} else {
folder = (Folder) folder.getParent();
}
}
return null;
}
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();
Account account = getRequestedAccount(zsc);
if (!canAccessAccount(zsc, account))
throw ServiceException.PERM_DENIED("can not access account");
List<DataSource> dataSources = prov.getAllDataSources(account);
Element response = zsc.createElement(MailConstants.GET_DATA_SOURCES_RESPONSE);
for (DataSource dsrc : dataSources) if (!dsrc.isInternal())
ToXML.encodeDataSource(response, dsrc);
return response;
}
use of com.zimbra.cs.account.DataSource in project zm-mailbox by Zimbra.
the class TestUtil method setDataSourceAttr.
public static void setDataSourceAttr(String userName, String dataSourceName, String attrName, String attrValue) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
Account account = getAccount(userName);
DataSource ds = prov.get(account, Key.DataSourceBy.name, dataSourceName);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(attrName, attrValue);
prov.modifyAttrs(ds, attrs);
}
Aggregations