View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.crm.service.user;
35  
36  import fr.paris.lutece.plugins.crm.business.user.CRMUser;
37  import fr.paris.lutece.plugins.crm.business.user.MokeCRMUser;
38  
39  import java.util.Map.Entry;
40  
41  /**
42   *
43   * MokeCRMUserService
44   *
45   */
46  public class MokeCRMUserService extends CRMUserService
47  {
48      private static final int ID_CRM_USER1 = 1;
49  
50      /**
51       * Find by primary key
52       * 
53       * @param nIdCRMUser
54       *            the id crm user
55       * @return a {@link CRMUser}
56       */
57      public CRMUser findByPrimaryKey( int nIdCRMUser )
58      {
59          CRMUser crmUser = new MokeCRMUser( nIdCRMUser );
60          System.out.println( trace( crmUser ) );
61  
62          return crmUser;
63      }
64  
65      /**
66       * Find from a given user guid
67       * 
68       * @param strUserGuid
69       *            the user guid
70       * @return a {@link CRMUser}
71       */
72      public CRMUser findByUserGuid( String strUserGuid )
73      {
74          CRMUser crmUser = new MokeCRMUser( ID_CRM_USER1 );
75          System.out.println( trace( crmUser ) );
76  
77          return crmUser;
78      }
79  
80      /**
81       * Create a new {@link CRMUser}
82       * 
83       * @param user
84       *            the {@link CRMUser}
85       * @return the new primary key
86       */
87      public int create( CRMUser user )
88      {
89          System.out.println( trace( user ) );
90  
91          return ID_CRM_USER1;
92      }
93  
94      /**
95       * Update a {@link CRMUser}
96       * 
97       * @param user
98       *            the {@link CRMUser}
99       */
100     public void update( CRMUser user )
101     {
102         System.out.println( trace( user ) );
103     }
104 
105     /**
106      * Remove a CRMUser
107      * 
108      * @param nIdCRMUser
109      *            the id crm user
110      */
111     public void remove( int nIdCRMUser )
112     {
113         System.out.println( trace( ) );
114     }
115 
116     /**
117      * Trace
118      * 
119      * @return trace
120      */
121     private String trace( )
122     {
123         return trace( null );
124     }
125 
126     /**
127      * Trace
128      * 
129      * @param crmUser
130      *            the crm user
131      * @return trace
132      */
133     private String trace( CRMUser crmUser )
134     {
135         StringBuilder sbTrace = new StringBuilder( );
136         sbTrace.append( "\n ---------------------- CRM User Service -------------------" );
137         sbTrace.append( "\nMethod name : " + Thread.currentThread( ).getStackTrace( ) [2].getMethodName( ) );
138 
139         if ( crmUser != null )
140         {
141             sbTrace.append( "\nid_crm_user : " + crmUser.getIdCRMUser( ) );
142             sbTrace.append( "\nuser_guid : " + crmUser.getUserGuid( ) );
143 
144             for ( Entry<String, String> userAttribute : crmUser.getUserAttributes( ).entrySet( ) )
145             {
146                 sbTrace.append( "\n" + userAttribute.getKey( ) + " : " + userAttribute.getValue( ) );
147             }
148         }
149 
150         sbTrace.append( "\n --------------------------------------------------------------------" );
151 
152         return sbTrace.toString( );
153     }
154 }