View Javadoc
1   /*
2    * Copyright (c) 2002-2024, 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.identityimport.business;
35  
36  import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
37  import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
38  import fr.paris.lutece.portal.service.plugin.Plugin;
39  import fr.paris.lutece.portal.service.plugin.PluginService;
40  import fr.paris.lutece.portal.service.spring.SpringContextService;
41  import fr.paris.lutece.util.ReferenceList;
42  
43  import java.util.List;
44  import java.util.Optional;
45  
46  /**
47   * This class provides instances management methods (create, find, ...) for Batch objects
48   */
49  public final class BatchHome
50  {
51      // Static variable pointed at the DAO instance
52      private static IBatchDAO _dao = SpringContextService.getBean( "identityimport.batchDAO" );
53      private static Plugin _plugin = PluginService.getPlugin( "identityimport" );
54  
55      /**
56       * Private constructor - this class need not be instantiated
57       */
58      private BatchHome( )
59      {
60      }
61  
62      /**
63       * Create an instance of the batch class
64       * 
65       * @param batch
66       *            The instance of the Batch which contains the information to store
67       * @return The instance of batch which has been created with its primary key.
68       */
69      public static Batchf="../../../../../../fr/paris/lutece/plugins/identityimport/business/Batch.html#Batch">Batch create( Batch batch )
70      {
71          _dao.insert( batch, _plugin );
72  
73          return batch;
74      }
75  
76      /**
77       * Update of the batch which is specified in parameter
78       * 
79       * @param batch
80       *            The instance of the Batch which contains the data to store
81       * @return The instance of the batch which has been updated
82       */
83      public static Batchf="../../../../../../fr/paris/lutece/plugins/identityimport/business/Batch.html#Batch">Batch update( Batch batch )
84      {
85          _dao.store( batch, _plugin );
86  
87          return batch;
88      }
89  
90      /**
91       * Remove the batch whose identifier is specified in parameter
92       * 
93       * @param nKey
94       *            The batch Id
95       */
96      public static void remove( int nKey )
97      {
98          _dao.delete( nKey, _plugin );
99      }
100 
101     /**
102      * Returns an instance of a batch whose identifier is specified in parameter
103      * 
104      * @param nKey
105      *            The batch primary key
106      * @return an instance of Batch
107      */
108     public static Optional<Batch> findByPrimaryKey( int nKey )
109     {
110         return _dao.load( nKey, _plugin );
111     }
112 
113     /**
114      * Load the data of all the batch objects and returns them as a list
115      * 
116      * @return the list which contains the data of all the batch objects
117      */
118     public static List<Batch> getBatchsList( )
119     {
120         return _dao.selectBatchsList( _plugin );
121     }
122 
123     /**
124      * Load the id of all the batch objects and returns them as a list
125      *
126      * @return the list which contains the id of all the batch objects
127      */
128     public static List<Integer> getIdBatchsList( final ResourceState resourceState, final String filterAppCode, final String filterClientCode, final String filterReference )
129     {
130         return _dao.selectIdBatchsList( resourceState.getId( ), filterAppCode, filterClientCode, filterReference, _plugin );
131     }
132 
133     /**
134      * Load the data of all the batch objects and returns them as a referenceList
135      * 
136      * @return the referenceList which contains the data of all the batch objects
137      */
138     public static ReferenceList getBatchsReferenceList( )
139     {
140         return _dao.selectBatchsReferenceList( _plugin );
141     }
142 
143     /**
144      * Load the data of all the avant objects and returns them as a list
145      * 
146      * @param listIds
147      *            liste of ids
148      * @return the list which contains the data of all the avant objects
149      */
150     public static List<Batch> getBatchsListByIds( List<Integer> listIds )
151     {
152         return _dao.selectBatchsListByIds( _plugin, listIds );
153     }
154 
155     public static Batch getBatch( final String reference )
156     {
157         return _dao.selectBatchByReference( _plugin, reference );
158     }
159 
160     public static Optional<Batch> getBatch( final int id )
161     {
162         return _dao.load( id, _plugin );
163     }
164 
165     /**
166      * Load the data of all the expired batch objects and returns them as a list. <br>
167      * A batch is considered expired if it is finalized and it's creation date exceeds data retention time of the client.
168      * 
169      * @return The list which contains the data of all the expired batch objects
170      */
171     public static List<Batch> findExpiredBatches( final int batchLimit )
172     {
173         return _dao.selectExpiredBatchsList( batchLimit, _plugin );
174     }
175 
176     /**
177      * Load the data of all the batches in the initial workflow state and returns them as a list
178      * 
179      * @param batchLimit
180      *            the limit
181      * @return batches in the initial workflow state
182      */
183     public static List<Batch> findInitialStateBatches( final int batchLimit )
184     {
185         return _dao.selectInitialStateBatches( batchLimit, _plugin );
186     }
187 
188     /**
189      * Load the data of all the batches in the initial workflow state and returns them as a list
190      *
191      * @param batchLimit
192      *            the limit
193      * @return batches in the initial workflow state
194      */
195     public static List<Batch> findClosableBatches( final int batchLimit )
196     {
197         return _dao.selectClosableBatches( batchLimit, _plugin );
198     }
199 
200     public static List<ResourceState> getBatchStates( final String filterAppCode, final String filterClientCode )
201     {
202         return _dao.selectBatchStates( filterAppCode, filterClientCode, _plugin );
203     }
204 
205     public static ResourceState getBatchState( final int batchId )
206     {
207         return _dao.selectBatchState( batchId, _plugin );
208     }
209 
210     public static int getIdentitiesCount( final int resourceId )
211     {
212         return _dao.countIdentities( resourceId, _plugin );
213     }
214 
215     public static List<ResourceHistory> getBatchHistory( final int batchId )
216     {
217         return _dao.getBatchHistory( batchId, _plugin );
218     }
219 
220     /**
221      * Get the id of the action for batches in initial state
222      * 
223      * @return the action id
224      */
225     public static int getBatchInitialActionId( ) throws IdentityStoreException
226     {
227         return _dao.getBatchInitialActionId( _plugin );
228     }
229 
230     /**
231      * Get the id of the action for batches in initial state
232      *
233      * @return the action id
234      */
235     public static int getBatchInTreatmentActionId( ) throws IdentityStoreException
236     {
237         return _dao.getBatchInTreatmentActionId( _plugin );
238     }
239 }