use of com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException in project zm-mailbox by Zimbra.
the class LdapProvisioning method createXMPPComponent.
@Override
public XMPPComponent createXMPPComponent(String name, Domain domain, Server server, Map<String, Object> inAttrs) throws ServiceException {
name = name.toLowerCase().trim();
// sanity checking
removeAttrIgnoreCase("objectclass", inAttrs);
removeAttrIgnoreCase(A_zimbraDomainId, inAttrs);
removeAttrIgnoreCase(A_zimbraServerId, inAttrs);
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
AttributeManager.getInstance().preModify(inAttrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_XMPPCOMPONENT);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(inAttrs);
entry.setAttr(A_objectClass, "zimbraXMPPComponent");
String compId = LdapUtil.generateUUID();
entry.setAttr(A_zimbraId, compId);
entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
entry.setAttr(A_cn, name);
String dn = mDIT.xmppcomponentNameToDN(name);
entry.setDN(dn);
entry.setAttr(A_zimbraDomainId, domain.getId());
entry.setAttr(A_zimbraServerId, server.getId());
zlc.createEntry(entry);
XMPPComponent comp = getXMPPComponentById(compId, zlc, true);
AttributeManager.getInstance().postModify(inAttrs, comp, callbackContext);
return comp;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.IM_COMPONENT_EXISTS(name);
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations