1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
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  /**
28   * <a href="ContactListener.java.html"><b><i>View Source</i></b></a>
29   *
30   * @author Scott Lee
31   * @author Brian Wing Shun Chan
32   * @author Raymond Augé
33   */
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  }