Search in sources :

Example 1 with ZimletPresence

use of com.zimbra.cs.zimlet.ZimletPresence in project zm-mailbox by Zimbra.

the class GetInfo method doZimlets.

private static void doZimlets(Element response, Account acct) {
    try {
        // bug 34517
        ZimletUtil.migrateUserPrefIfNecessary(acct);
        ZimletPresence userZimlets = ZimletUtil.getUserZimlets(acct);
        List<Zimlet> zimletList = ZimletUtil.orderZimletsByPriority(userZimlets.getZimletNamesAsArray());
        int priority = 0;
        for (Zimlet z : zimletList) {
            if (z.isEnabled() && !z.isExtension()) {
                ZimletUtil.listZimlet(response, z, priority, userZimlets.getPresence(z.getName()));
            }
            priority++;
        }
        // load the zimlets in the dev directory and list them
        ZimletUtil.listDevZimlets(response);
    } catch (ServiceException se) {
        ZimbraLog.account.error("can't get zimlets", se);
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) ServiceException(com.zimbra.common.service.ServiceException) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence)

Example 2 with ZimletPresence

use of com.zimbra.cs.zimlet.ZimletPresence in project zm-mailbox by Zimbra.

the class ModifyZimletPrefs method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Map<String, Object> attrs = new HashMap<String, Object>();
    ZimletPresence availZimlets = ZimletUtil.getAvailableZimlets(account);
    String addEnabled = "+" + Provisioning.A_zimbraPrefZimlets;
    String delEnabled = "-" + Provisioning.A_zimbraPrefZimlets;
    String addDisabled = "+" + Provisioning.A_zimbraPrefDisabledZimlets;
    String delDisabled = "-" + Provisioning.A_zimbraPrefDisabledZimlets;
    for (Element eZimlet : request.listElements(AccountConstants.E_ZIMLET)) {
        String zimletName = eZimlet.getAttribute(AccountConstants.A_NAME);
        String presense = eZimlet.getAttribute(AccountConstants.A_ZIMLET_PRESENCE);
        Presence userPrefPresence = Presence.fromString(presense);
        // user cannot make a zimlet mandatory
        if (userPrefPresence == Presence.mandatory)
            throw ServiceException.INVALID_REQUEST("invalid zimlet presence: " + presense, null);
        Presence defaultPresence = availZimlets.getPresence(zimletName);
        /*
             * if zimlet is not available to the user or is mandatory,
             * we don't want it to appear in either enabled/disabled prefs,
             * regardless what the user wants.
             * 
             * if default presence is the same as what user wants. it does not 
             * need to appear in the user pref.
             */
        if (// zimlet not available to the user
        defaultPresence == null || // zimlet is mandatory
        defaultPresence == Presence.mandatory || defaultPresence == userPrefPresence) {
            // default == what user wants
            StringUtil.addToMultiMap(attrs, delEnabled, zimletName);
            StringUtil.addToMultiMap(attrs, delDisabled, zimletName);
        } else {
            /*
                 * default != what user wants
                 */
            if (userPrefPresence == Presence.enabled) {
                // user wants the zimlet enabled
                StringUtil.addToMultiMap(attrs, addEnabled, zimletName);
                StringUtil.addToMultiMap(attrs, delDisabled, zimletName);
            } else {
                // user wants the zimlet disabled
                StringUtil.addToMultiMap(attrs, delEnabled, zimletName);
                StringUtil.addToMultiMap(attrs, addDisabled, zimletName);
            }
        }
    }
    Provisioning prov = Provisioning.getInstance();
    prov.modifyAttrs(account, attrs);
    Element response = zsc.createElement(AccountConstants.MODIFY_ZIMLET_PREFS_RESPONSE);
    doResponse(prov, response, account);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Presence(com.zimbra.cs.zimlet.ZimletPresence.Presence) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with ZimletPresence

use of com.zimbra.cs.zimlet.ZimletPresence in project zm-mailbox by Zimbra.

the class ModifyZimletPrefs method doResponse.

private void doResponse(Provisioning prov, Element response, Account acct) throws ServiceException {
    ZimletPresence userZimlets = ZimletUtil.getUserZimlets(acct);
    for (String zimletName : userZimlets.getZimletNames()) {
        Zimlet zimlet = prov.getZimlet(zimletName);
        if (zimlet != null && zimlet.isEnabled() && !zimlet.isExtension()) {
            Element eZimlet = response.addElement(AccountConstants.E_ZIMLET);
            eZimlet.addAttribute(AccountConstants.A_NAME, zimletName);
            eZimlet.addAttribute(AccountConstants.A_ZIMLET_PRESENCE, userZimlets.getPresence(zimletName).toString());
        }
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) Element(com.zimbra.common.soap.Element) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence)

Example 4 with ZimletPresence

use of com.zimbra.cs.zimlet.ZimletPresence in project zm-mailbox by Zimbra.

the class AvailableZimlets method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) {
    Object replacing = attrsToModify.get(attrName);
    Object deleting = attrsToModify.get("-" + attrName);
    Object adding = attrsToModify.get("+" + attrName);
    ZimletPresence availZimlets;
    if (replacing != null)
        availZimlets = doReplacing(replacing);
    else
        availZimlets = doDeletingAdding(entry, attrName, deleting, adding);
    String[] zimlets = availZimlets.getZimletNamesAsArray();
    String[] newValues = new String[zimlets.length];
    for (int i = 0; i < zimlets.length; i++) {
        String zimletName = zimlets[i];
        Presence presence = availZimlets.getPresence(zimletName);
        newValues[i] = presence.prefix() + zimletName;
    }
    // do the update using our re-shuffled values
    attrsToModify.remove(attrName);
    attrsToModify.remove("-" + attrName);
    attrsToModify.remove("+" + attrName);
    attrsToModify.put(attrName, newValues);
}
Also used : ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence) Presence(com.zimbra.cs.zimlet.ZimletPresence.Presence) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence)

Aggregations

ZimletPresence (com.zimbra.cs.zimlet.ZimletPresence)4 Element (com.zimbra.common.soap.Element)2 Zimlet (com.zimbra.cs.account.Zimlet)2 Presence (com.zimbra.cs.zimlet.ZimletPresence.Presence)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 HashMap (java.util.HashMap)1