Search in sources :

Example 26 with DataSource

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);
}
Also used : GetDataSourceUsageResponse(com.zimbra.soap.mail.message.GetDataSourceUsageResponse) Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DataSourceUsage(com.zimbra.soap.mail.message.DataSourceUsage) DataSource(com.zimbra.cs.account.DataSource)

Example 27 with DataSource

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;
}
Also used : Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ArrayList(java.util.ArrayList) Folder(com.zimbra.cs.mailbox.Folder) ZFolder(com.zimbra.client.ZFolder) ItemId(com.zimbra.cs.service.util.ItemId) ZMountpoint(com.zimbra.client.ZMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) DataSource(com.zimbra.cs.account.DataSource) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) HashSet(java.util.HashSet)

Example 28 with DataSource

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;
}
Also used : HashMap(java.util.HashMap) ImapFolder(com.zimbra.cs.datasource.imap.ImapFolder) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) DataSource(com.zimbra.cs.account.DataSource)

Example 29 with DataSource

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;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) DataSource(com.zimbra.cs.account.DataSource)

Example 30 with DataSource

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);
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ZDataSource(com.zimbra.client.ZDataSource) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

DataSource (com.zimbra.cs.account.DataSource)71 Account (com.zimbra.cs.account.Account)29 HashMap (java.util.HashMap)21 Provisioning (com.zimbra.cs.account.Provisioning)18 DbDataSource (com.zimbra.cs.db.DbDataSource)18 ServiceException (com.zimbra.common.service.ServiceException)15 Element (com.zimbra.common.soap.Element)14 Mailbox (com.zimbra.cs.mailbox.Mailbox)11 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)11 ArrayList (java.util.ArrayList)11 ZDataSource (com.zimbra.client.ZDataSource)8 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Folder (com.zimbra.cs.mailbox.Folder)7 DataSourceType (com.zimbra.soap.admin.type.DataSourceType)7 HashSet (java.util.HashSet)7 Test (org.junit.Test)7 DataSourceItem (com.zimbra.cs.db.DbDataSource.DataSourceItem)6 ZMailbox (com.zimbra.client.ZMailbox)5 LdapDataSource (com.zimbra.cs.account.ldap.entry.LdapDataSource)5 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5