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 @Override
035 public void onAfterCreate(Contact contact) throws ModelListenerException {
036 try {
037 exportToLDAP(contact);
038 }
039 catch (Exception e) {
040 throw new ModelListenerException(e);
041 }
042 }
043
044 @Override
045 public void onAfterUpdate(Contact contact) throws ModelListenerException {
046 try {
047 exportToLDAP(contact);
048 }
049 catch (Exception e) {
050 throw new ModelListenerException(e);
051 }
052 }
053
054 protected void exportToLDAP(Contact contact) throws Exception {
055 if (LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
056 return;
057 }
058
059 ServiceContext serviceContext =
060 ServiceContextThreadLocal.getServiceContext();
061
062 Map<String, Serializable> expandoBridgeAttributes = null;
063
064 if (serviceContext != null) {
065 expandoBridgeAttributes =
066 serviceContext.getExpandoBridgeAttributes();
067 }
068
069 PortalLDAPExporterUtil.exportToLDAP(contact, expandoBridgeAttributes);
070 }
071
072 }