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.occupation;
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.controller.demandes.AbstractCtvJspBean;
43  import fr.paris.lutece.plugins.ctv.service.ExecutantControllerService;
44  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeOccupationBoServiceImpl;
45  import fr.paris.lutece.plugins.ctv.service.IExecutantControllerService;
46  import fr.paris.lutece.plugins.ctv.service.IFormulaireDemandeOccupationBoService;
47  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
48  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
49  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
50  
51  @Controller( controllerJsp = "executant.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/occupation/etapes", right = "DEMANDE_OCCUPATION" )
52  public class ExecutantJspBean extends AbstractCtvJspBean
53  {
54  
55      private static final long serialVersionUID = -5935071488662220709L;
56  
57      // Service
58      private IExecutantControllerService executantControllerService = ExecutantControllerService.getInstance( );
59      protected IFormulaireDemandeOccupationBoService formulaireService = FormulaireDemandeOccupationBoServiceImpl.getInstance( );
60  
61      // Template
62      private static final String TEMPLATE_EXECUTANT = "admin/plugins/ctv/etapes/executant.html";
63  
64      // Title
65      private static final String EXECUTANT_TITLE = "ctv.etape.executant.travaux.title";
66  
67      private static final String VIEW_EXECUTANT = "executant";
68  
69      @View( defaultView = true, value = VIEW_EXECUTANT )
70      public String getExecutantView( HttpServletRequest request )
71      {
72          Map<String, Object> model = getModel( );
73          int numDemande = formulaireService.getNumDemande( request );
74          fillUserPossibleActions( request, model, numDemande );
75          fillModelForExecutant( request, model );
76          return getPage( EXECUTANT_TITLE, TEMPLATE_EXECUTANT, model );
77      }
78  
79      @Action( ACTION_SAVE )
80      public String doSaveAction( HttpServletRequest request )
81      {
82          executantControllerService.updateFromRequest( request );
83          int numDemande = formulaireService.getNumDemande( request );
84          fillLastUser( numDemande, request );
85  
86          // Récupération de la redirection
87          String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
88          if ( StringUtils.isNullOrEmpty( nextStepPath ) )
89          {
90              return redirect( request, "../demandeOccupation.jsp" );
91          }
92          return redirect( request, nextStepPath );
93      }
94  
95      @Action( ACTION_ABANDON )
96      public String abandon( HttpServletRequest request )
97      {
98          formulaireService.removeFilesFromSession( request );
99          String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
100         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
101         {
102             return redirect( request, "../demandeOccupation.jsp" );
103         }
104         return redirect( request, nextStepPath );
105     }
106 
107     private void fillModelForExecutant( HttpServletRequest request, Map<String, Object> model )
108     {
109         executantControllerService.initModel( model );
110         executantControllerService.alimenterModel( request, model );
111         formulaireService.alimentationModelBO( request, model );
112         int numDemande = formulaireService.getNumDemande( request );
113         fillUserPossibleActions( request, model, numDemande );
114         model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
115         model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
116         model.put( "controlForm", true );
117     }
118 
119 }