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.business.demand;
35  
36  import fr.paris.lutece.plugins.crm.service.CRMPlugin;
37  import fr.paris.lutece.portal.service.plugin.Plugin;
38  import fr.paris.lutece.portal.service.plugin.PluginService;
39  import fr.paris.lutece.portal.service.spring.SpringContextService;
40  import fr.paris.lutece.util.ReferenceList;
41  
42  import java.util.List;
43  
44  /**
45   *
46   * DemandTypeHome
47   *
48   */
49  public final class DemandTypeHome
50  {
51      private static final String BEAN_CRM_DEMANDTYPEDAO = "crm.demandTypeDAO";
52      private static Plugin _plugin = PluginService.getPlugin( CRMPlugin.PLUGIN_NAME );
53      private static IDemandTypeDAO _dao = SpringContextService.getBean( BEAN_CRM_DEMANDTYPEDAO );
54  
55      /**
56       * Private constructor - this class need not be instantiated
57       */
58      private DemandTypeHome( )
59      {
60      }
61  
62      /**
63       * Generates a new primary key
64       * 
65       * @return The new primary key
66       */
67      public static int newPrimaryKey( )
68      {
69          return _dao.newPrimaryKey( _plugin );
70      }
71  
72      /**
73       * Insert a new record in the table.
74       * 
75       * @param demandType
76       *            instance of the DemandType object to insert
77       * @return the key of the newly created demandType
78       */
79      public static int create( DemandType demandType )
80      {
81          return _dao.insert( demandType, _plugin );
82      }
83  
84      /**
85       * Update the record in the table
86       * 
87       * @param demandType
88       *            the reference of the demandType
89       */
90      public static void update( DemandType demandType )
91      {
92          _dao.store( demandType, _plugin );
93      }
94  
95      /**
96       * Delete a record from the table
97       * 
98       * @param nIdDemandType
99       *            int identifier of the demandType to delete
100      */
101     public static void remove( int nIdDemandType )
102     {
103         _dao.delete( nIdDemandType, _plugin );
104     }
105 
106     /**
107      * Load the data from the table
108      * 
109      * @param nIdDemandType
110      *            The identifier of the demandType
111      * @return The instance of the demandType
112      */
113     public static DemandType findByPrimaryKey( int nIdDemandType )
114     {
115         return _dao.load( nIdDemandType, _plugin );
116     }
117 
118     /**
119      * Find the demandType by its order
120      * 
121      * @param nOrder
122      *            the order
123      * @return a {@link DemandType}
124      */
125     public static DemandType findByOrder( int nOrder )
126     {
127         return _dao.selectByOrder( nOrder, _plugin );
128     }
129 
130     /**
131      * Find all demandTypes
132      * 
133      * @return a list of {@link DemandType}
134      */
135     public static List<DemandType> findAll( )
136     {
137         return _dao.selectAll( _plugin );
138     }
139 
140     /**
141      * Find the list of demandTypes by id category and date
142      * 
143      * @param nIdCategory
144      *            the ID category
145      * @param dateToday
146      *            the date of today
147      * @return a list of {@link DemandType}
148      */
149     public static List<DemandType> findByIdCategoryAndDate( int nIdCategory, java.util.Date dateToday )
150     {
151         return _dao.selectByIdCategoryAndDate( nIdCategory, dateToday, _plugin );
152     }
153 
154     /**
155      * Find all demandTypes as a {@link ReferenceList}
156      * 
157      * @return a {@link ReferenceList}
158      */
159     public static ReferenceList findDemandTypes( )
160     {
161         ReferenceList list = new ReferenceList( );
162 
163         for ( DemandType demandType : _dao.selectAll( _plugin ) )
164         {
165             list.addItem( demandType.getIdDemandType( ), demandType.getLabel( ) );
166         }
167 
168         return list;
169     }
170 
171     /**
172      * Find the max order
173      * 
174      * @return the max order
175      */
176     public static int findMaxOrder( )
177     {
178         return _dao.selectMaxOrder( _plugin );
179     }
180 
181     /**
182      * Find by filter
183      * 
184      * @param dtFilter
185      *            the filter
186      * @return a list of {@link DemandType}
187      */
188     public static List<DemandType> findByFilter( DemandTypeFilter dtFilter )
189     {
190         return _dao.selectDemandTypesByFilter( dtFilter, _plugin );
191     }
192 
193     /**
194      * Find demand types that have not a date end
195      * 
196      * @return a list of {@link DemandType}
197      */
198     public static List<DemandType> findNoDateEndDemandTypes( )
199     {
200         return _dao.selectNoDateEndDemandTypes( _plugin );
201     }
202 }