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.ctv.controller.front;
35  
36  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_CANCEL;
37  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_COMPLETE;
38  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_DELETE;
39  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_END_OF_WORKS;
40  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_PROLONGATION;
41  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.DEMANDEUR;
42  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.MON_ESPACE_DEMANDEUR;
43  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.NATURES_CHANTIER;
44  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.NOM_FICHIER;
45  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.PAGE_PORTAL;
46  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.SESSION_NUM_DEMANDE_ID;
47  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.TEMPLATE_MON_ESPACE_DEMANDEUR;
48  
49  import java.util.ArrayList;
50  import java.util.Comparator;
51  import java.util.Date;
52  import java.util.HashMap;
53  import java.util.List;
54  import java.util.Map;
55  import java.util.TreeMap;
56  
57  import javax.servlet.http.HttpServletRequest;
58  import javax.servlet.http.HttpSession;
59  
60  import org.apache.commons.beanutils.ConvertUtils;
61  import org.apache.commons.fileupload.FileItem;
62  
63  import fr.paris.lutece.plugins.ctv.bo.AlerteDemande.TypeAlerteDemande;
64  import fr.paris.lutece.plugins.ctv.bo.DemandeFinTravaux;
65  import fr.paris.lutece.plugins.ctv.bo.DemandeWithEmprises;
66  import fr.paris.lutece.plugins.ctv.bo.Emprise;
67  import fr.paris.lutece.plugins.ctv.bo.EmpriseId;
68  import fr.paris.lutece.plugins.ctv.bo.Prolongation;
69  import fr.paris.lutece.plugins.ctv.bo.StatutProlongation;
70  import fr.paris.lutece.plugins.ctv.business.IAlerteDemandeService;
71  import fr.paris.lutece.plugins.ctv.business.IChantierService;
72  import fr.paris.lutece.plugins.ctv.business.IDemandeFinTravauxService;
73  import fr.paris.lutece.plugins.ctv.business.IDemandeService;
74  import fr.paris.lutece.plugins.ctv.business.IEmpriseService;
75  import fr.paris.lutece.plugins.ctv.business.IProlongationService;
76  import fr.paris.lutece.plugins.ctv.business.IReferentielsService;
77  import fr.paris.lutece.plugins.ctv.constant.Document;
78  import fr.paris.lutece.plugins.ctv.constant.StatutDemande;
79  import fr.paris.lutece.plugins.ctv.constant.StatutEmprise;
80  import fr.paris.lutece.plugins.ctv.constant.TypeFinTravaux;
81  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
82  import fr.paris.lutece.plugins.ctv.converter.CustomDateConverter;
83  import fr.paris.lutece.plugins.ctv.handler.CtvUploadDemandeDocumentHandler;
84  import fr.paris.lutece.plugins.ctv.handler.CtvUploadEmpriseDocumentHandler;
85  import fr.paris.lutece.plugins.ctv.util.Utils;
86  import fr.paris.lutece.plugins.ctv.view.object.DemandeReading;
87  import fr.paris.lutece.portal.service.datastore.DatastoreService;
88  import fr.paris.lutece.portal.service.security.LuteceUser;
89  import fr.paris.lutece.portal.service.security.UserNotSignedException;
90  import fr.paris.lutece.portal.service.spring.SpringContextService;
91  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
92  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
93  import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
94  import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
95  import fr.paris.lutece.portal.web.xpages.XPage;
96  
97  @Controller( xpageName = MON_ESPACE_DEMANDEUR, pageTitleI18nKey = "ctv.page.mon.espace.title" )
98  public class MonEspaceDemandeurApp extends MVCApplication
99  {
100 
101     private static final long serialVersionUID = -6347744612049536082L;
102     public static final String COMPLETE_TRUE = "&complete=true";
103     public static final String VISUALISE_TRUE = "&visualise=true";
104 
105     private IDemandeService demandeService = SpringContextService.getBean( "demandeService" );
106     private IEmpriseService empriseService = SpringContextService.getBean( "empriseService" );
107     private IProlongationService prolongationService = SpringContextService.getBean( "prolongationService" );
108     private IChantierService chantierService = SpringContextService.getBean( "chantierService" );
109 
110     private IDemandeFinTravauxService demandeFinTravauxService = SpringContextService.getBean( "demandeFinTravauxService" );
111 
112     protected static IAlerteDemandeService alerteDemandeService = SpringContextService.getBean( "alerteDemandeService" );
113 
114     private static final CtvUploadDemandeDocumentHandler ctvDemandeUploadHandler = SpringContextService
115             .getBean( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER );
116     private static final CtvUploadEmpriseDocumentHandler ctvEmpriseUploadHandler = SpringContextService
117             .getBean( CtvUploadEmpriseDocumentHandler.CTV_EMPRISE_UPLOAD_HANDLER );
118 
119     private static IReferentielsService referentielsService = SpringContextService.getBean( "referentielsService" );
120 
121     @View( value = MON_ESPACE_DEMANDEUR, defaultView = true )
122     public XPage getChantier( HttpServletRequest request ) throws UserNotSignedException
123     {
124 
125         LuteceUser user = Utils.getUser( request );
126         String guid = user.getName( );
127 
128         int delaiRemiseEnCirculation = Integer
129                 .parseInt( DatastoreService.getDataValue( "parametre.numeric.prolongation.tolerance.declaration.fin.travaux", "7" ) );
130 
131         int toleranceDeclarationFinTravaux = Integer
132                 .parseInt( DatastoreService.getDataValue( "parametre.numeric.prolongation.date.prolongee.declaration.fin.travaux", "5" ) );
133 
134         Map<String, Object> model = new HashMap<>( );
135         List<DemandeReading> demandesInAlertes = demandeService.findDemandesInAlertes( guid );
136         demandeService.applyDelaiRemiseEnCirculationProlongation( demandesInAlertes, delaiRemiseEnCirculation, toleranceDeclarationFinTravaux );
137         model.put( "alertes", demandesInAlertes );
138 
139         // Statut BROUILLON
140         model.put( "brouillons", demandeService.findDemandesBrouillons( guid ) );
141 
142         // Statut A_TRAITER, A_SIGNER, A_VALIDER
143 
144         List<? extends DemandeReading> demandeEnCours = demandeService.findDemandeEnCours( guid );
145         model.put( "demandeEnCours", setFilesFromDemandeReading( request, demandeEnCours ) );
146 
147         // Statut SIGNE
148         List<? extends DemandeReading> travauxEnCours = demandeService.findTravauxEnCours( guid );
149         demandeService.applyDelaiRemiseEnCirculationProlongation( travauxEnCours, delaiRemiseEnCirculation, toleranceDeclarationFinTravaux );
150         model.put( "travauxEnCours", setFilesFromDemande( request, travauxEnCours ) );
151 
152         Map<String, Map<String, List<FileItem>>> documentsAutorisation = new HashMap<String, Map<String, List<FileItem>>>( );
153         for ( DemandeReading tc : travauxEnCours )
154         {
155             List<Emprise> emprises = empriseService.findEmprisesByDemandeId( tc.getDemandeNumero( ) );
156             for ( Emprise emprise : emprises )
157             {
158                 ctvEmpriseUploadHandler.removeFilesInSession( request );
159                 HttpSession session = request.getSession( );
160                 session.setAttribute( CtvConstants.EMPRISE_ID, emprise.getEmpriseId( ) );
161                 // GDM List<FileItem> uploadedFiles = ctvEmpriseUploadHandler.getListUploadedFiles( "autorisations", session );
162                 List<FileItem> uploadedFiles = new ArrayList<>( );
163 
164                 if ( documentsAutorisation.containsKey( Integer.toString( tc.getDemandeNumero( ) ) ) )
165                 {
166                     documentsAutorisation.get( Integer.toString( tc.getDemandeNumero( ) ) ).put( Integer.toString( emprise.getEmpriseId( ) ), uploadedFiles );
167                 }
168                 else
169                 {
170                     Map<String, List<FileItem>> doc = new HashMap<String, List<FileItem>>( );
171                     doc.put( Integer.toString( emprise.getEmpriseId( ) ), uploadedFiles );
172                     documentsAutorisation.put( Integer.toString( tc.getDemandeNumero( ) ), doc );
173                 }
174                 ctvEmpriseUploadHandler.removeFilesInSession( request );
175             }
176         }
177 
178         model.put( "documentsAutorisationTravauxEnCour", documentsAutorisation );
179 
180         // Statut Clos
181         List<DemandeWithEmprises> demandesCloture = demandeService.findDemandesCloture( guid );
182         model.put( "demandeCloturees", setFilesFromDemande( request, demandesCloture ) );
183 
184         Map<String, Map<String, List<FileItem>>> documentsAutorisationDemandeCloturee = new HashMap<String, Map<String, List<FileItem>>>( );
185         for ( DemandeWithEmprises dc : demandesCloture )
186         {
187             for ( EmpriseId emprise : dc.getEmpriseIds( ) )
188             {
189                 ctvEmpriseUploadHandler.removeFilesInSession( request );
190                 HttpSession session = request.getSession( );
191                 session.setAttribute( CtvConstants.EMPRISE_ID, emprise.getEmpriseId( ) );
192                 // GDM List<FileItem> uploadedFiles = ctvEmpriseUploadHandler.getListUploadedFiles( "autorisations", session );
193                 List<FileItem> uploadedFiles = new ArrayList<>( );
194 
195                 if ( documentsAutorisationDemandeCloturee.containsKey( Integer.toString( dc.getDemandeNumero( ) ) ) )
196                 {
197                     documentsAutorisationDemandeCloturee.get( Integer.toString( dc.getDemandeNumero( ) ) ).put( Integer.toString( emprise.getEmpriseId( ) ),
198                             uploadedFiles );
199                 }
200                 else
201                 {
202                     Map<String, List<FileItem>> doc = new HashMap<String, List<FileItem>>( );
203                     doc.put( Integer.toString( emprise.getEmpriseId( ) ), uploadedFiles );
204                     documentsAutorisationDemandeCloturee.put( Integer.toString( dc.getDemandeNumero( ) ), doc );
205                 }
206                 ctvEmpriseUploadHandler.removeFilesInSession( request );
207             }
208         }
209         model.put( "documentsAutorisationDemandeCloturee", documentsAutorisationDemandeCloturee );
210 
211         model.put( NATURES_CHANTIER, referentielsService.getNatureTravauxOccupation( ) );
212 
213         return getXPage( TEMPLATE_MON_ESPACE_DEMANDEUR, request.getLocale( ), model );
214 
215     }
216 
217     private Map<DemandeWithEmprises, List<FileItem>> setFilesFromDemande( HttpServletRequest request, List<? extends DemandeReading> demandeWithEmprises )
218     {
219 
220         Map<DemandeWithEmprises, List<FileItem>> mapResult = new HashMap<>( );
221         for ( DemandeReading demandeWithEmprise : demandeWithEmprises )
222         {
223             int demandeNumero = demandeWithEmprise.getDemandeNumero( );
224             // GDM List<FileItem> fileList = getFileItemList( request, demandeNumero );
225             List<FileItem> fileList = new ArrayList<>( );
226             mapResult.put( (DemandeWithEmprises) demandeWithEmprise, fileList );
227 
228         }
229 
230         Map<DemandeWithEmprises, List<FileItem>> sortedMap = new TreeMap<DemandeWithEmprises, List<FileItem>>( new Comparator<DemandeWithEmprises>( )
231         {
232             @Override
233             public int compare( DemandeWithEmprises d1, DemandeWithEmprises d2 )
234             {
235                 return ( new Integer( d1.getDemandeNumero( ) ) ).compareTo( ( new Integer( d2.getDemandeNumero( ) ) ) );
236             }
237         } );
238         sortedMap.putAll( mapResult );
239 
240         return sortedMap;
241     }
242 
243     private Map<DemandeReading, List<FileItem>> setFilesFromDemandeReading( HttpServletRequest request, List<? extends DemandeReading> demandeEnCours )
244     {
245 
246         Map<DemandeReading, List<FileItem>> mapResult = new HashMap<>( );
247         for ( DemandeReading demandeReading : demandeEnCours )
248         {
249             int demandeNumero = demandeReading.getDemandeNumero( );
250             // GDM List<FileItem> fileList = getFileItemList( request, demandeNumero );
251             List<FileItem> fileList = new ArrayList<>( );
252             mapResult.put( demandeReading, fileList );
253 
254         }
255 
256         Map<DemandeReading, List<FileItem>> sortedMap = new TreeMap<DemandeReading, List<FileItem>>( new Comparator<DemandeReading>( )
257         {
258             @Override
259             public int compare( DemandeReading d1, DemandeReading d2 )
260             {
261                 return ( new Integer( d1.getDemandeNumero( ) ) ).compareTo( ( new Integer( d2.getDemandeNumero( ) ) ) );
262             }
263         } );
264         sortedMap.putAll( mapResult );
265 
266         return sortedMap;
267     }
268 
269     @Action( ACTION_COMPLETE )
270     public XPage complete( HttpServletRequest request )
271     {
272         int demandeId = Integer.parseInt( request.getParameter( "demande_id" ) );
273         request.getSession( ).setAttribute( SESSION_NUM_DEMANDE_ID, demandeId );
274         return redirect( request, PAGE_PORTAL + DEMANDEUR + COMPLETE_TRUE );
275     }
276 
277     @Action( ACTION_DELETE )
278     public XPage delete( HttpServletRequest request )
279     {
280         int demandeId = Integer.parseInt( request.getParameter( "demande_id" ) );
281         demandeService.updateDemandeStatut( demandeId, StatutDemande.ANNULEE );
282         empriseService.updateStatutAllEmprises( demandeId, StatutEmprise.ANNULEE, false );
283         demandeService.updateDemandeAnnulee( true, demandeId );
284         alerteDemandeService.insertAlerte( TypeAlerteDemande.ANNULEE, demandeId );
285 
286         return redirect( request, PAGE_PORTAL + MON_ESPACE_DEMANDEUR );
287     }
288 
289     @Action( ACTION_CANCEL )
290     public XPage cancel( HttpServletRequest request )
291     {
292         int demandeId = Integer.parseInt( request.getParameter( "demande_id" ) );
293         demandeService.updateDemandeStatut( demandeId, StatutDemande.ANNULEE );
294         demandeService.updateDemandeAnnulee( true, demandeId );
295         alerteDemandeService.insertAlerte( TypeAlerteDemande.ANNULEE, demandeId );
296 
297         return redirect( request, PAGE_PORTAL + MON_ESPACE_DEMANDEUR );
298     }
299 
300     @Action( ACTION_END_OF_WORKS )
301     public XPage endofworks( HttpServletRequest request )
302     {
303         int demandeId = Integer.parseInt( request.getParameter( "demande_id" ) );
304         demandeService.updateDemandeStatut( demandeId, StatutDemande.CLOS );
305         return redirect( request, PAGE_PORTAL + MON_ESPACE_DEMANDEUR );
306     }
307 
308     @Action( ACTION_PROLONGATION )
309     public XPage prolongation( HttpServletRequest request )
310     {
311         ConvertUtils.register( new CustomDateConverter( ), Date.class );
312         Emprise empriseRequest = new Emprise( );
313         populate( empriseRequest, request );
314         int empriseId = empriseRequest.getEmpriseId( );
315 
316         Emprise emprise = empriseService.findEmpriseById( empriseId );
317         if ( empriseRequest.getEmpriseDateFin( ) != null )
318         {
319             emprise.setEmpriseDateFinRemiseEnCirculationGestion( empriseRequest.getEmpriseDateFin( ) );
320             emprise.setEmpriseDateFinTravauxReseauGestion( empriseRequest.getEmpriseDateFin( ) );
321             emprise.setEmpriseDateFinTravauxVoirieGestion( empriseRequest.getEmpriseDateFin( ) );
322         }
323 
324         Prolongation prolongation = new Prolongation( );
325         prolongation.setProlongationHorodatageDeclaration( new Date( ) );
326         prolongation.setProlongationEmpriseId( empriseId );
327         prolongation.setProlongationStatut( StatutProlongation.DEMANDEE );
328 
329         DemandeFinTravaux demandeFinTravaux = demandeFinTravauxService.findDemandeFinTravauxByEmpriseId( empriseId );
330 
331         // Si fin de travaux réseau validée alors on récupère la date acceptée
332         if ( ( emprise.getEmpriseDateFinTravauxReseauAcceptee( ) != null ) && ( demandeFinTravaux != null )
333                 && ( demandeFinTravaux.getFinTravauxReseauxHorodatageValidation( ) != null ) )
334         {
335             prolongation.setProlongationReseauxDeclaree( emprise.getEmpriseDateFinTravauxReseauAcceptee( ) );
336         }
337         else
338         {
339             prolongation.setProlongationReseauxDeclaree( emprise.getEmpriseDateFinTravauxReseauGestion( ) );
340         }
341 
342         // Si fin de travaux voirie validée alors on récupère la date acceptée
343         if ( ( emprise.getEmpriseDateFinTravauxVoirieAcceptee( ) != null ) && ( demandeFinTravaux != null )
344                 && ( demandeFinTravaux.getFinTravauxVoirieHorodatageValidation( ) != null ) )
345         {
346             prolongation.setProlongationVoirieDeclaree( emprise.getEmpriseDateFinTravauxVoirieAcceptee( ) );
347         }
348         else
349         {
350             prolongation.setProlongationVoirieDeclaree( emprise.getEmpriseDateFinTravauxReseauGestion( ) );
351         }
352 
353         // Si fin de travaux circulation validée alors on récupèra la date acceptée
354         if ( ( emprise.getEmpriseDateFinRemiseEnCirculationAcceptee( ) != null ) && ( demandeFinTravaux != null )
355                 && ( demandeFinTravaux.getFinTravauxCirculationHorodatageValidation( ) != null ) )
356         {
357             prolongation.setProlongationCirculationDeclaree( emprise.getEmpriseDateFinRemiseEnCirculationAcceptee( ) );
358         }
359         else
360         {
361             prolongation.setProlongationCirculationDeclaree( emprise.getEmpriseDateFinTravauxReseauGestion( ) );
362         }
363 
364         String prolongationMotif = request.getParameter( "prolongationMotif" );
365         prolongation.setProlongationMotif( prolongationMotif );
366         prolongationService.insertProlongation( prolongation );
367         empriseService.updateEmprise( empriseId, emprise, false );
368         empriseService.updateStatut( empriseId, StatutEmprise.PROLONGATION );
369 
370         return redirect( request, PAGE_PORTAL + MON_ESPACE_DEMANDEUR );
371     }
372 
373     @Action( "display_details" )
374     public XPage displayDetails( HttpServletRequest request )
375     {
376         return redirect( request, PAGE_PORTAL + MON_ESPACE_DEMANDEUR );
377     }
378 
379     @Action( "downLoadFront" )
380     public XPage downLoadFront( HttpServletRequest request )
381     {
382         String fileName = request.getParameter( NOM_FICHIER );
383         Integer numDemande = Integer.parseInt( request.getParameter( "numDemande" ) );
384         byte [ ] content = null;
385         // GDM List<FileItem> fileList = getFileItemList( request, numDemande );
386         List<FileItem> fileList = new ArrayList<>( );
387         for ( FileItem file : fileList )
388         {
389             String itemName = file.getName( );
390             if ( itemName.equals( fileName ) )
391             {
392                 content = file.get( );
393                 return download( content, itemName, itemName );
394             }
395         }
396         return null;
397     }
398 
399     @Action( "declaration_fin_travaux" )
400     public XPage declarationFinTravaux( HttpServletRequest request )
401     {
402 
403         int empriseId = Integer.parseInt( request.getParameter( "empriseId" ) );
404         ConvertUtils.register( new CustomDateConverter( ), Date.class );
405         Emprise myEmprise = empriseService.findEmpriseById( empriseId );
406 
407         Emprise emprise = new Emprise( );
408         populate( emprise, request );
409 
410         if ( empriseId > 0 )
411         {
412             DemandeFinTravaux demandeFinTravaux = demandeFinTravauxService.findDemandeFinTravauxByEmpriseId( empriseId );
413             Date dateRenseignee = emprise.getEmpriseDateFin( );
414 
415             if ( ( demandeFinTravaux == null ) || ( demandeFinTravaux.getFinTravauxReseauxHorodatageDeclaration( ) == null ) )
416             {
417                 if ( demandeFinTravaux == null )
418                 {
419                     demandeFinTravaux = new DemandeFinTravaux( );
420                     demandeFinTravaux.setFinTravauxEmpriseId( empriseId );
421                 }
422                 setReseauxItems( myEmprise, demandeFinTravaux, dateRenseignee );
423                 setVoirieItems( myEmprise, demandeFinTravaux, dateRenseignee );
424                 setCirculationItemsAndUpdateEmpriseAndFinTravaux( empriseId, myEmprise, demandeFinTravaux, dateRenseignee, StatutEmprise.FIN_TRAVAUX_RESEAUX );
425             }
426             else
427                 if ( ( demandeFinTravaux.getFinTravauxReseauxHorodatageDeclaration( ) != null )
428                         && ( demandeFinTravaux.getFinTravauxVoirieHorodatageDeclaration( ) == null ) )
429                 {
430                     setVoirieItems( myEmprise, demandeFinTravaux, dateRenseignee );
431                     setCirculationItemsAndUpdateEmpriseAndFinTravaux( empriseId, myEmprise, demandeFinTravaux, dateRenseignee,
432                             StatutEmprise.FIN_TRAVAUX_VOIRIE );
433                 }
434                 else
435                     if ( ( demandeFinTravaux.getFinTravauxVoirieHorodatageDeclaration( ) != null )
436                             && ( demandeFinTravaux.getFinTravauxCirculationHorodatageDeclaration( ) == null ) )
437                     {
438                         setCirculationItemsAndUpdateEmpriseAndFinTravaux( empriseId, myEmprise, demandeFinTravaux, dateRenseignee,
439                                 StatutEmprise.REMISE_EN_CIRCULATION );
440                     }
441         }
442         return redirect( request, PAGE_PORTAL + MON_ESPACE_DEMANDEUR );
443     }
444 
445     private void setReseauxItems( Emprise myEmprise, DemandeFinTravaux demandeFinTravaux, Date dateRenseignee )
446     {
447         myEmprise.setEmpriseDateFinTravauxReseauGestion( dateRenseignee );
448         demandeFinTravaux.setFinTravauxReseauxHorodatageDeclaration( new Date( ) );
449         demandeFinTravaux.setFinTravauxReseauxDeclaree( dateRenseignee );
450     }
451 
452     private void setVoirieItems( Emprise myEmprise, DemandeFinTravaux demandeFinTravaux, Date dateRenseignee )
453     {
454         myEmprise.setEmpriseDateFinTravauxVoirieGestion( dateRenseignee );
455         demandeFinTravaux.setFinTravauxVoirieDeclaree( dateRenseignee );
456         demandeFinTravaux.setFinTravauxVoirieHorodatageDeclaration( new Date( ) );
457     }
458 
459     private void setCirculationItemsAndUpdateEmpriseAndFinTravaux( int empriseId, Emprise myEmprise, DemandeFinTravaux demandeFinTravaux, Date dateRenseignee,
460             StatutEmprise statut )
461     {
462         myEmprise.setEmpriseDateFinRemiseEnCirculationGestion( dateRenseignee );
463         empriseService.updateStatut( empriseId, statut );
464         empriseService.updateEmprise( empriseId, myEmprise, false );
465 
466         demandeFinTravaux.setFinTravauxType( TypeFinTravaux.OCCUPATION_DECLAREE );
467         demandeFinTravaux.setFinTravauxCirculationDeclaree( dateRenseignee );
468         demandeFinTravaux.setFinTravauxCirculationHorodatageDeclaration( new Date( ) );
469 
470         demandeFinTravauxService.upsertDemandeFinTravaux( demandeFinTravaux );
471     }
472 
473     @Action( "saisie_commentaires" )
474     public XPage saisieCommentaires( HttpServletRequest request )
475     {
476         int empriseId = Integer.parseInt( request.getParameter( "empriseId" ) );
477         String commentaire = request.getParameter( "commentaireDemandeur" );
478         empriseService.updateCommentaireDemandeur( empriseId, commentaire );
479         return redirectView( request, MON_ESPACE_DEMANDEUR );
480     }
481 
482     private List<FileItem> getFileItemList( HttpServletRequest request, int demandeNumero )
483     {
484         HttpSession session = request.getSession( );
485         session.setAttribute( CtvConstants.SESSION_NUM_DEMANDE_ID, Integer.toString( demandeNumero ) );
486         ctvDemandeUploadHandler.removeFilesInSession( request );
487         List<FileItem> fileList = ctvDemandeUploadHandler.getListUploadedFiles( Document.ROC_PV, session );
488         fileList.addAll( ctvDemandeUploadHandler.getListUploadedFiles( Document.ROC_AUTRES, session ) );
489         fileList.addAll( ctvDemandeUploadHandler.getListUploadedFiles( Document.SAISINE_AUTRE_SERVICE, session ) );
490         fileList.addAll( ctvDemandeUploadHandler.getListUploadedFiles( Document.SAISINE_COMMISSARIAT, session ) );
491         fileList.addAll( ctvDemandeUploadHandler.getListUploadedFiles( Document.SAISINE_PREFECTURE_POLICE, session ) );
492         session.removeAttribute( CtvConstants.SESSION_NUM_DEMANDE_ID );
493         ctvDemandeUploadHandler.removeFilesInSession( request );
494         return fileList;
495     }
496 
497 }