Search in sources :

Example 1 with GetDistributionListMembershipRequest

use of com.zimbra.soap.admin.message.GetDistributionListMembershipRequest in project zm-mailbox by Zimbra.

the class GetDistributionListMembership method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetDistributionListMembershipRequest req = JaxbUtil.elementToJaxb(request);
    int limit = (req.getLimit() == null) ? 0 : req.getLimit();
    if (limit < 0) {
        throw ServiceException.INVALID_REQUEST("limit" + limit + " is negative", null);
    }
    int offset = (req.getOffset() == null) ? 0 : req.getOffset();
    if (offset < 0) {
        throw ServiceException.INVALID_REQUEST("offset" + offset + " is negative", null);
    }
    DistributionListSelector dlSel = req.getDl();
    DistributionListBy dlBy = dlSel.getBy().toKeyDistributionListBy();
    String dlKey = dlSel.getKey();
    DistributionList distributionList = prov.get(dlBy, dlKey);
    defendAgainstGroupHarvesting(distributionList, dlBy, dlKey, zsc, Admin.R_getDistributionListMembership, /* shouldn't be used */
    Admin.R_getDistributionListMembership);
    HashMap<String, String> via = new HashMap<String, String>();
    List<DistributionList> lists = prov.getDistributionLists(distributionList, false, via);
    Element response = zsc.createElement(AdminConstants.GET_DISTRIBUTION_LIST_MEMBERSHIP_RESPONSE);
    for (DistributionList dl : lists) {
        Element dlEl = response.addNonUniqueElement(AdminConstants.E_DL);
        dlEl.addAttribute(AdminConstants.A_NAME, dl.getName());
        dlEl.addAttribute(AdminConstants.A_ID, dl.getId());
        String viaDl = via.get(dl.getName());
        if (viaDl != null)
            dlEl.addAttribute(AdminConstants.A_VIA, viaDl);
    }
    return response;
}
Also used : GetDistributionListMembershipRequest(com.zimbra.soap.admin.message.GetDistributionListMembershipRequest) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) Element(com.zimbra.common.soap.Element) DistributionListSelector(com.zimbra.soap.admin.type.DistributionListSelector) Provisioning(com.zimbra.cs.account.Provisioning) DistributionList(com.zimbra.cs.account.DistributionList)

Aggregations

DistributionListBy (com.zimbra.common.account.Key.DistributionListBy)1 Element (com.zimbra.common.soap.Element)1 DistributionList (com.zimbra.cs.account.DistributionList)1 Provisioning (com.zimbra.cs.account.Provisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GetDistributionListMembershipRequest (com.zimbra.soap.admin.message.GetDistributionListMembershipRequest)1 DistributionListSelector (com.zimbra.soap.admin.type.DistributionListSelector)1 HashMap (java.util.HashMap)1