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 java.util.Map;
37  
38  import javax.servlet.http.HttpServletRequest;
39  
40  import com.mysql.jdbc.StringUtils;
41  
42  import fr.paris.lutece.plugins.ctv.bo.EntiteDemande;
43  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
44  import fr.paris.lutece.plugins.ctv.business.IEntiteDemandeService;
45  import fr.paris.lutece.plugins.ctv.service.ExecutantInterventionControllerService;
46  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeInterventionServiceImpl;
47  import fr.paris.lutece.plugins.ctv.service.IExecutantControllerService;
48  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
49  import fr.paris.lutece.portal.service.spring.SpringContextService;
50  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
51  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
52  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
53  
54  @Controller( controllerJsp = "executant.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/intervention/etapes", right = "TABLEAU_DE_BORD" )
55  public class ExecutantJspBean extends AbstractCtvJspBean
56  {
57  
58      private static final long serialVersionUID = -5935071488662220709L;
59  
60      // Template
61      private static final String TEMPLATE_EXECUTANT = "/admin/plugins/ctv/demandeIntervention/etapesIntervention/executant.html";
62  
63      protected IFormulaire formulaireInterventionService = FormulaireDemandeInterventionServiceImpl.getInstance( );
64  
65      private IExecutantControllerService executantControllerService = ExecutantInterventionControllerService.getInstance( );
66  
67      // Title
68      private static final String EXECUTANT_TITLE = "ctv.etape.intervention.travaux.title";
69  
70      private IFormulaire formulaireService = FormulaireDemandeInterventionServiceImpl.getInstance( );
71      private IEntiteDemandeService entiteDemandeService = SpringContextService.getBean( "entiteDemandeService" );
72  
73      private static final String VIEW_EXECUTANT = "executant";
74  
75      @View( defaultView = true, value = VIEW_EXECUTANT )
76      public String getExecutantView( HttpServletRequest request )
77      {
78          Map<String, Object> model = getModel( );
79          int numDemande = formulaireInterventionService.getNumDemande( request );
80          fillUserPossibleActions( request, model, numDemande );
81          fillModelForExecutant( request, model );
82          checkingExistingErrors( request, model, numDemande );
83          return getPage( EXECUTANT_TITLE, TEMPLATE_EXECUTANT, model );
84      }
85  
86      @Action( ACTION_NEXT )
87      public String next( HttpServletRequest request )
88      {
89          executantControllerService.updateFromRequest( request );
90          int numDemande = formulaireInterventionService.getNumDemande( request );
91          fillLastUser( numDemande, request );
92          return redirect( request, "emprises.jsp" );
93      }
94  
95      @Action( ACTION_ABANDON )
96      public String abandon( HttpServletRequest request )
97      {
98          formulaireInterventionService.removeFilesFromSession( request );
99          String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
100         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
101         {
102             return redirect( request, "../demandeIntervention.jsp" );
103         }
104         return redirect( request, nextStepPath );
105     }
106 
107     @Action( ACTION_COMPLETE_LATER )
108     public String completeLater( HttpServletRequest request )
109     {
110         executantControllerService.updateFromRequest( request );
111         formulaireService.removeFilesFromSession( request );
112         int numDemande = formulaireInterventionService.getNumDemande( request );
113         fillLastUser( numDemande, request );
114         return redirect( request, getAbsolutePath( request, PATH_TABLEAU_DE_BORD ) );
115     }
116 
117     @Action( ACTION_SAVE )
118     public String save( HttpServletRequest request )
119     {
120         executantControllerService.updateFromRequest( request );
121         int numDemande = formulaireInterventionService.getNumDemande( request );
122         fillLastUser( numDemande, request );
123         // Récupération de la redirection
124         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
125         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
126         {
127             return redirect( request, "../demandeIntervention.jsp" );
128         }
129         return redirect( request, nextStepPath );
130     }
131 
132     private void fillModelForExecutant( HttpServletRequest request, Map<String, Object> model )
133     {
134         executantControllerService.initModel( model );
135         executantControllerService.alimenterModel( request, model );
136         model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
137         model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
138     }
139 
140     private void checkingExistingErrors( HttpServletRequest request, Map<String, Object> model, int numDemande )
141     {
142         EntiteDemande entiteExecutantDemande = entiteDemandeService.getExecutantByNumDemande( numDemande );
143         if ( request.getParameter( "complete" ) != null || entiteExecutantDemande != null )
144         {
145             model.put( "controlForm", true );
146         }
147     }
148 
149 }