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);
}
}
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;
}
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());
}
}
}
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);
}
Aggregations