View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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.portal.business.user.attribute;
35  
36  import fr.paris.lutece.portal.service.spring.SpringContextService;
37  
38  import java.util.List;
39  import java.util.Locale;
40  
41  /**
42   *
43   * AttributeHome
44   *
45   */
46  public final class AttributeHome
47  {
48      private static IAttributeDAO _dao = SpringContextService.getBean( "attributeDAO" );
49  
50      /**
51       * Private constructor
52       */
53      private AttributeHome( )
54      {
55      }
56  
57      /**
58       * Load attribute
59       * 
60       * @param nIdAttribute
61       *            ID Attribute
62       * @param locale
63       *            Locale
64       * @return Attribute
65       */
66      public static IAttribute findByPrimaryKey( int nIdAttribute, Locale locale )
67      {
68          return _dao.load( nIdAttribute, locale );
69      }
70  
71      /**
72       * Insert an new attribute
73       * 
74       * @param attribute
75       *            attribute
76       * @return new PK
77       */
78      public static int create( IAttribute attribute )
79      {
80          return _dao.insert( attribute );
81      }
82  
83      /**
84       * Update an attribute
85       * 
86       * @param attribute
87       *            the attribute
88       */
89      public static void update( IAttribute attribute )
90      {
91          _dao.store( attribute );
92      }
93  
94      /**
95       * Delete an attribute
96       * 
97       * @param nIdAttribute
98       *            The id of the attribute
99       */
100     public static void remove( int nIdAttribute )
101     {
102         _dao.delete( nIdAttribute );
103     }
104 
105     /**
106      * Load every attributes
107      * 
108      * @param locale
109      *            locale
110      * @return list of attributes
111      */
112     public static List<IAttribute> findAll( Locale locale )
113     {
114         return _dao.selectAll( locale );
115     }
116 
117     /**
118      * Load every attributes associated to a plugin
119      * 
120      * @param strPluginName
121      *            plugin name
122      * @param locale
123      *            locale
124      * @return list of attributes
125      */
126     public static List<IAttribute> findPluginAttributes( String strPluginName, Locale locale )
127     {
128         return _dao.selectPluginAttributes( strPluginName, locale );
129     }
130 
131     /**
132      * Load every attributes that do not come from a plugin
133      * 
134      * @param locale
135      *            locale
136      * @return list of attributes
137      */
138     public static List<IAttribute> findCoreAttributes( Locale locale )
139     {
140         return _dao.selectCoreAttributes( locale );
141     }
142 
143     /**
144      * Update the anonymization status of the attribute.
145      * 
146      * @param nIdAttribute
147      *            Id of the attribute
148      * @param bAnonymize
149      *            New value of the anonymization status. True means the attribute should be anonymize, false means it doesn't.
150      */
151     public static void updateAttributeAnonymization( int nIdAttribute, boolean bAnonymize )
152     {
153         _dao.updateAttributeAnonymization( nIdAttribute, bAnonymize );
154     }
155 }