Search in sources :

Example 16 with Zimlet

use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.

the class ProvTestUtil method createZimlet.

public Zimlet createZimlet(String zimletName, Map<String, Object> attrs) throws Exception {
    Zimlet zimlet = prov.createZimlet(zimletName, attrs);
    createdEntries.add(zimlet);
    return zimlet;
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet)

Example 17 with Zimlet

use of com.zimbra.cs.account.Zimlet 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 18 with Zimlet

use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.

the class CreateZimlet method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext lc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    String name = request.getAttribute(AdminConstants.E_NAME).toLowerCase();
    Map<String, Object> attrs = AdminService.getAttrs(request, true);
    checkRight(lc, context, null, Admin.R_createZimlet);
    checkSetAttrsOnCreate(lc, TargetType.zimlet, name, attrs);
    Zimlet zimlet = prov.createZimlet(name, attrs);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateZimlet", "name", name }, attrs));
    Element response = lc.createElement(AdminConstants.CREATE_ZIMLET_RESPONSE);
    GetZimlet.encodeZimlet(response, zimlet);
    return response;
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 19 with Zimlet

use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.

the class ModifyZimlet method doPriority.

void doPriority(ZimbraSoapContext zsc, Map<String, Object> context, Element z) throws ServiceException {
    String name = z.getAttribute(AdminConstants.A_NAME);
    Zimlet zimlet = Provisioning.getInstance().getZimlet(name);
    if (zimlet == null)
        throw AccountServiceException.NO_SUCH_ZIMLET(name);
    Element p = z.getElement(AdminConstants.E_PRIORITY);
    int val = (int) p.getAttributeLong(AdminConstants.A_VALUE, -1);
    if (val == -1)
        return;
    // ===========
    // check right
    //
    // need right to modify zimbraZimletPriority on *all* zimlets, because
    // all zimlets can be re-prioritized.
    Map<String, String> attrRightNeeded = new HashMap<String, String>();
    // yuck, pass null for the value
    attrRightNeeded.put(Provisioning.A_zimbraZimletPriority, null);
    List<Zimlet> allZimlets = Provisioning.getInstance().listAllZimlets();
    for (Zimlet zl : allZimlets) {
        checkRight(zsc, context, zl, attrRightNeeded);
    }
    //
    // end check right
    // ===============
    ZimletUtil.setPriority(name, val);
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element)

Example 20 with Zimlet

use of com.zimbra.cs.account.Zimlet in project zm-mailbox by Zimbra.

the class ZimletUtil method setPriority.

public static void setPriority(Zimlet z, int priority, List<Zimlet> plist) throws ServiceException {
    // XXX LdapEntry.equals() is not implemented
    for (Zimlet zim : plist) {
        if (zim.compareTo(z) == 0) {
            plist.remove(zim);
            break;
        }
    }
    if (priority == P_MAX) {
        priority = plist.size();
    }
    Version newPriority;
    if (priority == 0) {
        newPriority = new Version("0");
        setPriority(z, newPriority.toString());
        plist.add(0, z);
        if (plist.size() > 1) {
            // make sure the previous p0 zimlet is now p1.
            Zimlet p0zimlet = plist.get(1);
            setPriority(p0zimlet, 1, plist);
        }
    } else {
        // take the priority of previous zimlet
        Zimlet oneAbove = plist.get(priority - 1);
        String pString = oneAbove.getPriority();
        if (pString == null) {
            // priority is mandatory now, but it could be from old version
            // when we didn't have priorities.
            pString = Integer.toString(priority);
        }
        newPriority = new Version(pString);
        if (priority < plist.size()) {
            // increment, while staying before the next zimlet
            Zimlet oneBelow = plist.get(priority);
            pString = oneBelow.getPriority();
            if (pString == null) {
                pString = Integer.toString(priority + 2);
            }
            Version nextPriority = new Version(pString);
            if (newPriority.compareTo(nextPriority) < 0) {
                newPriority.increment(nextPriority);
            } else {
                // it really is an error because priorities of two zimlets
                // shouldn't be the same.  bump the next one down
                newPriority.increment();
                setPriority(z, newPriority.toString());
                plist.add(priority, z);
                setPriority(oneBelow, priority + 1, plist);
                return;
            }
        } else {
            // simply increment from the previous priority
            newPriority.increment();
        }
        setPriority(z, newPriority.toString());
    }
    try {
        flushCache();
    } catch (Exception e) {
        Throwable t = e.getCause();
        if (t instanceof ServiceException) {
            throw (ServiceException) t;
        }
        if (e instanceof IOException) {
            t = e;
        }
        throw ServiceException.FAILURE("unable to set priority", t);
    }
}
Also used : Zimlet(com.zimbra.cs.account.Zimlet) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException)

Aggregations

Zimlet (com.zimbra.cs.account.Zimlet)37 Provisioning (com.zimbra.cs.account.Provisioning)16 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)11 Element (com.zimbra.common.soap.Element)8 HashMap (java.util.HashMap)8 ServiceException (com.zimbra.common.service.ServiceException)7 AccountServiceException (com.zimbra.cs.account.AccountServiceException)7 Cos (com.zimbra.cs.account.Cos)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Entry (com.zimbra.cs.account.Entry)3 NamedEntry (com.zimbra.cs.account.NamedEntry)3 LdapZimlet (com.zimbra.cs.account.ldap.entry.LdapZimlet)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)2 ZimbraACE (com.zimbra.cs.account.accesscontrol.ZimbraACE)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Key (com.zimbra.common.account.Key)1 AccountBy (com.zimbra.common.account.Key.AccountBy)1 DistributionListBy (com.zimbra.common.account.Key.DistributionListBy)1