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