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.bo.controller.demandes.intervention;
35  
36  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_DOWNLOAD;
37  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.DETAILS_EMPRISE;
38  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ETAPE_EMPRISE;
39  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.KEY_ETAPE;
40  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.RECAP_EMPRISES;
41  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.RELOAD_CARTO;
42  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.TEMPLATE_RECAP_EMPRISES_INTERVENTION;
43  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.VALIDATE_CARTO;
44  
45  import java.util.Map;
46  import java.util.Set;
47  
48  import javax.servlet.http.HttpServletRequest;
49  
50  import org.apache.commons.fileupload.FileItem;
51  
52  import com.mysql.jdbc.StringUtils;
53  
54  import fr.paris.lutece.plugins.ctv.bo.DetailsEmprise;
55  import fr.paris.lutece.plugins.ctv.bo.DetailsEmprise.TypeConfigurationSpecifique;
56  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
57  import fr.paris.lutece.plugins.ctv.business.IChantierService;
58  import fr.paris.lutece.plugins.ctv.constant.Document;
59  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
60  import fr.paris.lutece.plugins.ctv.handler.CtvUploadDemandeDocumentHandler;
61  import fr.paris.lutece.plugins.ctv.handler.CtvUploadEmpriseDocumentHandler;
62  import fr.paris.lutece.plugins.ctv.service.EmpriseInterventionControllerService;
63  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeInterventionServiceImpl;
64  import fr.paris.lutece.plugins.ctv.service.IEmpriseControllerService;
65  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
66  import fr.paris.lutece.plugins.ctv.util.EmpriseMappingUtils;
67  import fr.paris.lutece.portal.service.spring.SpringContextService;
68  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
69  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
70  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
71  
72  @Controller( controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/intervention/etapes", controllerJsp = "emprises.jsp", right = "TABLEAU_DE_BORD" )
73  public class EmpriseJspBean extends AbstractCtvJspBean
74  {
75  
76      private static final long serialVersionUID = 2872842115920125391L;
77  
78      private IEmpriseControllerService empriseCtrlService = EmpriseInterventionControllerService.getInstance( );
79      protected static final IChantierService chantierService = SpringContextService.getBean( "chantierService" );
80      protected CtvUploadDemandeDocumentHandler ctvDemandeUploadHandler = SpringContextService
81              .getBean( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER );
82      private CtvUploadEmpriseDocumentHandler ctvUploadEmpriseDocumentHandler = SpringContextService
83              .getBean( CtvUploadEmpriseDocumentHandler.CTV_EMPRISE_UPLOAD_HANDLER );
84      protected IFormulaire formulaireInterventionService = FormulaireDemandeInterventionServiceImpl.getInstance( );
85  
86      @View( value = ETAPE_EMPRISE, defaultView = true )
87      public String getRecapEmprises( HttpServletRequest request )
88      {
89          Map<String, Object> model = getModel( );
90          int numDemande = formulaireInterventionService.getNumDemande( request );
91          fillUserPossibleActions( request, model, numDemande );
92          empriseCtrlService.initModel( model, request );
93          empriseCtrlService.alimenterModel( request, model );
94          model.put( KEY_ETAPE, "emprises" );
95          model.put( "controlForm", true );
96          return getPage( "", TEMPLATE_RECAP_EMPRISES_INTERVENTION, model );
97      }
98  
99      @View( value = DETAILS_EMPRISE )
100     public String getDetailsEmprise( HttpServletRequest request )
101     {
102         Map<String, Object> model = getModel( );
103         empriseCtrlService.fillModelForDetailEmprise( request, model );
104         int numDemande = formulaireInterventionService.getNumDemande( request );
105         fillUserPossibleActions( request, model, numDemande );
106         model.put( "controlForm", true );
107         return getPage( "", "admin/plugins/ctv/demandeIntervention/etapesIntervention/detailsEmpriseIntervention.html", model );
108     }
109 
110     @Action( "save_details_emprise" )
111     public String saveDetailsEmprise( HttpServletRequest request )
112     {
113         empriseCtrlService.updateEmpriseFromRequest( request, false );
114         storeFiles( request );
115         int numDemande = formulaireInterventionService.getNumDemande( request );
116         chantierService.updateDateChantierFromEmprises( numDemande );
117         fillLastUser( numDemande, request );
118         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
119         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
120         {
121             return redirectView( request, RECAP_EMPRISES );
122         }
123         return redirect( request, nextStepPath );
124     }
125 
126     @Action( ACTION_SAVE )
127     public String save( HttpServletRequest request )
128     {
129         empriseCtrlService.updateEmpriseFromRequest( request, false );
130         storeFiles( request );
131         int numDemande = formulaireInterventionService.getNumDemande( request );
132         chantierService.updateDateChantierFromEmprises( numDemande );
133         fillLastUser( numDemande, request );
134         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
135         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
136         {
137             return redirectView( request, RECAP_EMPRISES );
138         }
139         else
140             if ( nextStepPath.contains( DETAILS_EMPRISE ) )
141             {
142                 return redirectView( request, DETAILS_EMPRISE );
143             }
144             else
145             {
146                 return redirect( request, nextStepPath );
147             }
148     }
149 
150     private void storeFiles( HttpServletRequest request )
151     {
152         DetailsEmprise details = new DetailsEmprise( );
153         EmpriseMappingUtils.map( request, details );
154         Set<TypeConfigurationSpecifique> configurationsSpecifiques = details.getConfigurationsSpecifiques( );
155         if ( configurationsSpecifiques != null && ( configurationsSpecifiques.contains( TypeConfigurationSpecifique.EMPRISE_MODIFIANT_SOL )
156                 || configurationsSpecifiques.contains( TypeConfigurationSpecifique.EMPRISE_MODIFIANT_SOUS_SOL ) ) )
157         {
158             ctvUploadEmpriseDocumentHandler.storeFilesOnDisk( request, Document.FORMULAIRE_MULTI_CASES );
159         }
160     }
161 
162     @Action( ACTION_DOWNLOAD )
163     public void download( HttpServletRequest request )
164     {
165         String typeFichier = request.getParameter( CtvConstants.TYPE_FICHIER );
166         String nomFichier = request.getParameter( CtvConstants.NOM_FICHIER );
167         FileItem fileItem = ctvUploadEmpriseDocumentHandler.getFileItemByName( request, typeFichier, nomFichier );
168         if ( fileItem != null )
169         {
170             download( fileItem.get( ), fileItem.getName( ), fileItem.getName( ) );
171         }
172     }
173 
174     @Action( VALIDATE_CARTO )
175     public String validateCarto( HttpServletRequest request )
176     {
177         empriseCtrlService.updateEmpriseFromRequest( request, true );
178         int numDemande = formulaireInterventionService.getNumDemande( request );
179         fillLastUser( numDemande, request );
180         return redirectView( request, DETAILS_EMPRISE );
181     }
182 
183     @Action( RELOAD_CARTO )
184     public String reloadCarto( HttpServletRequest request )
185     {
186         return redirectView( request, DETAILS_EMPRISE );
187     }
188 
189     @Action( ACTION_NEXT )
190     public String next( HttpServletRequest request )
191     {
192         return redirect( request, "documents.jsp" );
193     }
194 
195     @Action( ACTION_COMPLETE_LATER )
196     public String completeLater( HttpServletRequest request )
197     {
198         formulaireInterventionService.removeFilesFromSession( request );
199         return redirect( request, getAbsolutePath( request, PATH_TABLEAU_DE_BORD ) );
200     }
201 
202     @Action( ACTION_ABANDON )
203     public String abandon( HttpServletRequest request )
204     {
205         formulaireInterventionService.removeFilesFromSession( request );
206         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
207         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
208         {
209             return redirect( request, "../demandeIntervention.jsp" );
210         }
211         else
212             if ( nextStepPath.contains( DETAILS_EMPRISE ) )
213             {
214                 return redirectView( request, DETAILS_EMPRISE );
215             }
216             else
217             {
218                 return redirect( request, nextStepPath );
219             }
220     }
221 
222 }