View Javadoc
1   /*
2    * Copyright (c) 2002-2023, 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.document.business.attributes;
35  
36  import fr.paris.lutece.plugins.document.business.DocumentType;
37  import fr.paris.lutece.portal.service.i18n.I18nService;
38  import fr.paris.lutece.portal.service.spring.SpringContextService;
39  
40  import java.util.Collection;
41  import java.util.List;
42  import java.util.Locale;
43  
44  /**
45   * This class provides instances management methods (create, find, ...) for DocumentAttribute objects
46   */
47  public final class DocumentAttributeHome
48  {
49      // Static variable pointed at the DAO instance
50      private static IDocumentAttributeDAO _dao = SpringContextService.getBean( "document.documentAttributeDAO" );
51  
52      /**
53       * Private constructor - this class need not be instantiated
54       */
55      private DocumentAttributeHome( )
56      {
57      }
58  
59      /**
60       * Creation of an instance of documentAttribute
61       *
62       * @param documentAttribute
63       *            The instance of the documentAttribute which contains the informations to store
64       * @return The instance of documentAttribute which has been created with its primary key.
65       */
66      public static DocumentAttribute../../../../fr/paris/lutece/plugins/document/business/attributes/DocumentAttribute.html#DocumentAttribute">DocumentAttribute create( DocumentAttribute documentAttribute )
67      {
68          _dao.insert( documentAttribute );
69  
70          return documentAttribute;
71      }
72  
73      /**
74       * Update of the documentAttribute which is specified in parameter
75       *
76       * @param documentAttribute
77       *            The instance of the documentAttribute which contains the data to store
78       * @return The instance of the documentAttribute which has been updated
79       */
80      public static DocumentAttribute../../../../fr/paris/lutece/plugins/document/business/attributes/DocumentAttribute.html#DocumentAttribute">DocumentAttribute update( DocumentAttribute documentAttribute )
81      {
82          _dao.store( documentAttribute );
83  
84          return documentAttribute;
85      }
86  
87      /**
88       * Remove the DocumentAttribute whose identifier is specified in parameter
89       *
90       * @param nAttributeId
91       *            The id of the attribute
92       */
93      public static void remove( int nAttributeId )
94      {
95          _dao.delete( nAttributeId );
96      }
97  
98      ///////////////////////////////////////////////////////////////////////////
99      // Finders
100 
101     /**
102      * Returns an instance of a documentAttribute whose identifier is specified in parameter
103      *
104      * @param nKey
105      *            The Primary key of the documentAttribute
106      * @return An instance of documentAttribute
107      */
108     public static DocumentAttribute findByPrimaryKey( int nKey )
109     {
110         return _dao.load( nKey );
111     }
112 
113     /**
114      * Returns a collection of documentAttributes objects
115      * 
116      * @param documentType
117      *            The document type
118      */
119     public static void setDocumentTypeAttributes( DocumentType documentType )
120     {
121         _dao.selectAttributesByDocumentType( documentType );
122     }
123 
124     /**
125      * Get all attributes of document type
126      * 
127      * @param codeDocumentType
128      *            The code document Type
129      * @return listDocumentAttributes The list of all attributes of selected code document type
130      */
131     public static List<DocumentAttribute> selectAllAttributesOfDocumentType( String codeDocumentType )
132     {
133         return _dao.selectAllAttributesOfDocumentType( codeDocumentType );
134     }
135 
136     /**
137      * Get the attribute type parameters of an attribute
138      * 
139      * @param nAttributeId
140      *            The id of the attribute to get the parameter of
141      * @param locale
142      *            The locale
143      * @return The list of parameters
144      */
145     public static Collection<AttributeTypeParameter> getAttributeParametersValues( int nAttributeId, Locale locale )
146     {
147         Collection<AttributeTypeParameter> listParametersValues = _dao.selectAttributeParametersValues( nAttributeId );
148 
149         return I18nService.localizeCollection( listParametersValues, locale );
150     }
151 
152     /**
153      * Get the list of values of a parameters of an attribute
154      * 
155      * @param nAttributeId
156      *            The id of the attribute
157      * @param strParameterName
158      *            The name of the parameter
159      * @return The list of values of the parameter of the attribute
160      */
161     public static List<String> getAttributeParameterValues( int nAttributeId, String strParameterName )
162     {
163         return _dao.getAttributeParameterValues( nAttributeId, strParameterName );
164     }
165 
166     /**
167      * Inserts a regular expression in the attribute
168      *
169      * @param nIdAttribute
170      *            The identifier of the document attribute
171      * @param nIdExpression
172      *            The identifier of the regular expression
173      */
174     public static void insertRegularExpression( int nIdAttribute, int nIdExpression )
175     {
176         _dao.insertRegularExpression( nIdAttribute, nIdExpression );
177     }
178 
179     /**
180      * Deletes a regular expression in the attribute
181      *
182      * @param nIdAttribute
183      *            The identifier of the document attribute
184      * @param nIdExpression
185      *            The identifier of the regular expression
186      */
187     public static void deleteRegularExpression( int nIdAttribute, int nIdExpression )
188     {
189         _dao.deleteRegularExpression( nIdAttribute, nIdExpression );
190     }
191 
192     /**
193      * Loads all regular expression key associated to the attribute and returns them into a collection
194      *
195      * @param nIdAttribute
196      *            The identifier of the document attribute
197      * @return A collection of regular expression key
198      */
199     public static Collection<Integer> getListRegularExpressionKeyByIdAttribute( int nIdAttribute )
200     {
201         return _dao.selectListRegularExpressionKeyByIdAttribute( nIdAttribute );
202     }
203 }