001
014
015 package com.liferay.portal.model;
016
017 import com.liferay.portal.ModelListenerException;
018 import com.liferay.portal.security.ldap.LDAPUserTransactionThreadLocal;
019 import com.liferay.portal.security.ldap.PortalLDAPExporterUtil;
020 import com.liferay.portal.service.ServiceContext;
021 import com.liferay.portal.service.ServiceContextThreadLocal;
022
023 import java.io.Serializable;
024
025 import java.util.Map;
026
027
032 public class ContactListener extends BaseModelListener<Contact> {
033
034 public void onAfterCreate(Contact contact) throws ModelListenerException {
035 try {
036 exportToLDAP(contact);
037 }
038 catch (Exception e) {
039 throw new ModelListenerException(e);
040 }
041 }
042
043 public void onAfterUpdate(Contact contact) throws ModelListenerException {
044 try {
045 exportToLDAP(contact);
046 }
047 catch (Exception e) {
048 throw new ModelListenerException(e);
049 }
050 }
051
052 protected void exportToLDAP(Contact contact) throws Exception {
053 if (LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
054 return;
055 }
056
057 ServiceContext serviceContext =
058 ServiceContextThreadLocal.getServiceContext();
059
060 Map<String, Serializable> expandoBridgeAttributes = null;
061
062 if (serviceContext != null) {
063 expandoBridgeAttributes =
064 serviceContext.getExpandoBridgeAttributes();
065 }
066
067 PortalLDAPExporterUtil.exportToLDAP(contact, expandoBridgeAttributes);
068 }
069
070 }