1
14
15 package com.liferay.portal.model;
16
17 import com.liferay.portal.ModelListenerException;
18 import com.liferay.portal.security.ldap.LDAPUserTransactionThreadLocal;
19 import com.liferay.portal.security.ldap.PortalLDAPExporterUtil;
20 import com.liferay.portal.service.ServiceContext;
21 import com.liferay.portal.service.ServiceContextThreadLocal;
22
23 import java.io.Serializable;
24
25 import java.util.Map;
26
27
34 public class ContactListener extends BaseModelListener<Contact> {
35
36 public void onAfterCreate(Contact contact) throws ModelListenerException {
37 try {
38 exportToLDAP(contact);
39 }
40 catch (Exception e) {
41 throw new ModelListenerException(e);
42 }
43 }
44
45 public void onAfterUpdate(Contact contact) throws ModelListenerException {
46 try {
47 exportToLDAP(contact);
48 }
49 catch (Exception e) {
50 throw new ModelListenerException(e);
51 }
52 }
53
54 protected void exportToLDAP(Contact contact) throws Exception {
55 if (LDAPUserTransactionThreadLocal.isOriginatesFromLDAP()) {
56 return;
57 }
58
59 ServiceContext serviceContext =
60 ServiceContextThreadLocal.getServiceContext();
61
62 Map<String, Serializable> expandoBridgeAttributes = null;
63
64 if (serviceContext != null) {
65 expandoBridgeAttributes =
66 serviceContext.getExpandoBridgeAttributes();
67 }
68
69 PortalLDAPExporterUtil.exportToLDAP(contact, expandoBridgeAttributes);
70 }
71
72 }