View Javadoc
1   /*
2    * Copyright (c) 2002-2021, City of 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.mylutece.business.attribute;
35  
36  import fr.paris.lutece.portal.service.plugin.Plugin;
37  import fr.paris.lutece.portal.service.spring.SpringContextService;
38  
39  import java.util.List;
40  import java.util.Locale;
41  import java.util.Map;
42  
43  /**
44   *
45   * AttributeHome
46   *
47   */
48  public class AttributeHome
49  {
50      private static IAttributeDAO _dao = SpringContextService.getBean( "mylutece.myLuteceAttributeDAO" );
51  
52      /**
53       * Load attribute
54       * 
55       * @param nIdAttribute
56       *            ID Attribute
57       * @param locale
58       *            Locale
59       * @param plugin
60       *            The plugin
61       * @return Attribute
62       */
63      public static IAttribute findByPrimaryKey( int nIdAttribute, Locale locale, Plugin plugin )
64      {
65          return _dao.load( nIdAttribute, locale, plugin );
66      }
67  
68      /**
69       * Insert an new attribute
70       * 
71       * @param attribute
72       *            attribute
73       * @param plugin
74       *            The plugin
75       * @return new PK
76       */
77      public static int create( IAttribute attribute, Plugin plugin )
78      {
79          return _dao.insert( attribute, plugin );
80      }
81  
82      /**
83       * Update an attribute
84       * 
85       * @param attribute
86       *            the attribute
87       * @param plugin
88       *            The plugin
89       */
90      public static void update( IAttribute attribute, Plugin plugin )
91      {
92          _dao.store( attribute, plugin );
93      }
94  
95      /**
96       * Delete an attribute
97       * 
98       * @param nIdAttribute
99       *            The id of the attribute
100      * @param plugin
101      *            The plugin
102      */
103     public static void remove( int nIdAttribute, Plugin plugin )
104     {
105         _dao.delete( nIdAttribute, plugin );
106     }
107 
108     /**
109      * Load every attributes
110      * 
111      * @param locale
112      *            locale
113      * @param plugin
114      *            The plugin
115      * @return list of attributes
116      */
117     public static List<IAttribute> findAll( Locale locale, Plugin plugin )
118     {
119         return _dao.selectAll( locale, plugin );
120     }
121 
122     /**
123      * Load every attributes associated to a plugin
124      * 
125      * @param strPluginName
126      *            plugin name
127      * @param locale
128      *            locale
129      * @param plugin
130      *            The plugin
131      * @return list of attributes
132      */
133     public static List<IAttribute> findPluginAttributes( String strPluginName, Locale locale, Plugin plugin )
134     {
135         return _dao.selectPluginAttributes( strPluginName, locale, plugin );
136     }
137 
138     /**
139      * Load every attributes that do not come from a plugin
140      * 
141      * @param locale
142      *            locale
143      * @param plugin
144      *            The plugin
145      * @return list of attributes
146      */
147     public static List<IAttribute> findMyLuteceAttributes( Locale locale, Plugin plugin )
148     {
149         return _dao.selectMyLuteceAttributes( locale, plugin );
150     }
151 
152     /**
153      * Update the anonymization status of the attribute.
154      * 
155      * @param nIdAttribute
156      *            Id of the attribute
157      * @param bAnonymize
158      *            New value of the anonymization status. True means the attribute should be anonymize, false means it doesn't.
159      * @param plugin
160      *            The plugin
161      */
162     public static void updateAttributeAnonymization( int nIdAttribute, boolean bAnonymize, Plugin plugin )
163     {
164         _dao.updateAttributeAnonymization( nIdAttribute, bAnonymize, plugin );
165     }
166 
167     /**
168      * Get a map of anonymization status of a user field.
169      * 
170      * @param plugin
171      *            The plugin
172      * @return A map containing the associations of user field name and a boolean describing whether the field should be anonymized.
173      */
174     public static Map<String, Boolean> getAnonymizationStatusUserStaticField( Plugin plugin )
175     {
176         return _dao.selectAnonymizationStatusUserStaticField( plugin );
177     }
178 
179     /**
180      * Add an anonymization status to a user field.
181      * 
182      * @param strFieldName
183      *            Name of the field
184      * @param bAnonymizeFiled
185      *            True if the field should be anonymize, false otherwise
186      * @param plugin
187      *            The plugin
188      */
189     public static void addAnonymizationStatusUserField( String strFieldName, boolean bAnonymizeFiled, Plugin plugin )
190     {
191         _dao.addAnonymizationStatusUserField( strFieldName, bAnonymizeFiled, plugin );
192     }
193 
194     /**
195      * Remove an anonymization status of a user field.
196      * 
197      * @param strFieldName
198      *            Name of the field
199      * @param plugin
200      *            The plugin
201      */
202     public static void removeAnonymizationStatusUserField( String strFieldName, Plugin plugin )
203     {
204         _dao.removeAnonymizationStatusUserField( strFieldName, plugin );
205     }
206 
207     /**
208      * Update the anonymization status of a user field.
209      * 
210      * @param strFieldName
211      *            Name of the field to update
212      * @param bAnonymizeFiled
213      *            True if the field should be anonymize, false otherwise
214      * @param plugin
215      *            The plugin
216      */
217     public static void updateAnonymizationStatusUserStaticField( String strFieldName, boolean bAnonymizeFiled, Plugin plugin )
218     {
219         _dao.updateAnonymizationStatusUserStaticField( strFieldName, bAnonymizeFiled, plugin );
220     }
221 }