001
014
015 package com.liferay.portal.model;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019 import com.liferay.portal.security.ldap.LDAPUserTransactionThreadLocal;
020 import com.liferay.portal.security.ldap.PortalLDAPExporterUtil;
021 import com.liferay.portal.service.ServiceContext;
022 import com.liferay.portal.service.ServiceContextThreadLocal;
023
024 import java.io.Serializable;
025
026 import java.util.Map;
027
028
033 public class ContactListener extends BaseModelListener<Contact> {
034
035 @Override
036 public void onAfterCreate(Contact contact) {
037 try {
038 exportToLDAP(contact);
039 }
040 catch (Exception e) {
041 _log.error(
042 "Unable to export contact with user ID " + contact.getUserId() +
043 " to LDAP on after create",
044 e);
045 }
046 }
047
048 @Override
049 public void onAfterUpdate(Contact contact) {
050 try {
051 exportToLDAP(contact);
052 }
053 catch (Exception e) {
054 _log.error(
055 "Unable to export contact with user ID " + contact.getUserId() +
056 " to LDAP on after update",
057 e);
058 }
059 }
060
061 protected void exportToLDAP(Contact contact) throws Exception {
062 if (LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
063 return;
064 }
065
066 ServiceContext serviceContext =
067 ServiceContextThreadLocal.getServiceContext();
068
069 Map<String, Serializable> expandoBridgeAttributes = null;
070
071 if (serviceContext != null) {
072 expandoBridgeAttributes =
073 serviceContext.getExpandoBridgeAttributes();
074 }
075
076 PortalLDAPExporterUtil.exportToLDAP(contact, expandoBridgeAttributes);
077 }
078
079 private static Log _log = LogFactoryUtil.getLog(ContactListener.class);
080
081 }