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.ETAPE_CHANTIER;
37  
38  import java.util.Map;
39  
40  import javax.servlet.http.HttpServletRequest;
41  
42  import com.mysql.jdbc.StringUtils;
43  
44  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
45  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
46  import fr.paris.lutece.plugins.ctv.service.ChantierInterventionControllerService;
47  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeInterventionServiceImpl;
48  import fr.paris.lutece.plugins.ctv.service.IChantierControllerService;
49  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
50  import fr.paris.lutece.plugins.ctv.view.object.DemandeReading;
51  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
52  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
53  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
54  
55  @Controller( controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/intervention/etapes", controllerJsp = "chantier.jsp", right = "TABLEAU_DE_BORD" )
56  public class ChantierJspBean extends AbstractCtvJspBean
57  {
58  
59      private static final long serialVersionUID = 1395119821735608990L;
60  
61      protected IFormulaire formulaireInterventionService = FormulaireDemandeInterventionServiceImpl.getInstance( );
62      private IChantierControllerService chantierControllerService = ChantierInterventionControllerService.getInstance( );
63  
64      @View( value = ETAPE_CHANTIER, defaultView = true )
65      public String getChantier( HttpServletRequest request )
66      {
67          Map<String, Object> model = getModel( );
68          int numDemande = formulaireInterventionService.getNumDemande( request );
69          fillUserPossibleActions( request, model, numDemande );
70          chantierControllerService.initModel( model );
71          chantierControllerService.alimenterModel( request, model );
72          checkingExistingErrors( request, model, numDemande );
73          return getPage( "", CtvConstants.TEMPLATE_CHANTIER_INTERVENTION, model );
74      }
75  
76      @Action( ACTION_NEXT )
77      public String next( HttpServletRequest request )
78      {
79          updateChantier( request );
80          return redirect( request, "executant.jsp" );
81      }
82  
83      @Action( ACTION_COMPLETE_LATER )
84      public String completeLater( HttpServletRequest request )
85      {
86          updateChantier( request );
87          formulaireInterventionService.removeFilesFromSession( request );
88          return redirect( request, getAbsolutePath( request, PATH_TABLEAU_DE_BORD ) );
89      }
90  
91      @Action( ACTION_SAVE )
92      public String save( HttpServletRequest request )
93      {
94          updateChantier( request );
95          // Récupération de la redirection
96          String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
97          if ( StringUtils.isNullOrEmpty( nextStepPath ) )
98          {
99              return redirect( request, "../demandeIntervention.jsp" );
100         }
101         return redirect( request, nextStepPath );
102     }
103 
104     @Action( ACTION_ABANDON )
105     public String abandon( HttpServletRequest request )
106     {
107         formulaireInterventionService.removeFilesFromSession( request );
108         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
109         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
110         {
111             return redirect( request, "../demandeIntervention.jsp" );
112         }
113         return redirect( request, nextStepPath );
114     }
115 
116     private void updateChantier( HttpServletRequest request )
117     {
118         chantierControllerService.registerConverters( );
119         chantierControllerService.updateFromRequest( request );
120         int numDemande = formulaireInterventionService.getNumDemande( request );
121         demandeService.updateIsChantierStepSeen( numDemande, true );
122         fillLastUser( numDemande, request );
123     }
124 
125     private void checkingExistingErrors( HttpServletRequest request, Map<String, Object> model, int numDemande )
126     {
127         DemandeReading maDemande = demandeService.findByNumDemande( numDemande );
128         if ( request.getParameter( "complete" ) != null || maDemande.isDemandeIsChantierStepSeen( ) )
129         {
130             model.put( "controlForm", true );
131         }
132     }
133 
134 }