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.ChantierControllerService;
44  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeOccupationBoServiceImpl;
45  import fr.paris.lutece.plugins.ctv.service.IChantierControllerService;
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 = "chantier.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/occupation/etapes", right = "DEMANDE_OCCUPATION" )
52  public class ChantierJspBean extends AbstractCtvJspBean
53  {
54  
55      private static final long serialVersionUID = -5906084384644405383L;
56  
57      // Template
58      private static final String TEMPLATE_CHANTIER = "admin/plugins/ctv/etapes/chantier.html";
59  
60      // Title
61      private static final String CHANTIER_TITLE = "ctv.etape.chantier.title";
62  
63      private static final String VIEW_CHANTIER = "chantier";
64  
65      // Service
66      private IChantierControllerService chantierControllerService = ChantierControllerService.getInstance( );
67      protected IFormulaireDemandeOccupationBoService formulaireService = FormulaireDemandeOccupationBoServiceImpl.getInstance( );
68  
69      @View( defaultView = true, value = VIEW_CHANTIER )
70      public String getChantierView( HttpServletRequest request )
71      {
72          Map<String, Object> model = getModel( );
73          int numDemande = formulaireService.getNumDemande( request );
74          fillUserPossibleActions( request, model, numDemande );
75          fillModelForChantier( request, model );
76          if ( request.getParameter( "complete" ) != null )
77          {
78              model.put( "controlForm", true );
79          }
80          return getPage( CHANTIER_TITLE, TEMPLATE_CHANTIER, model );
81      }
82  
83      @Action( ACTION_SAVE )
84      public String doSaveAction( HttpServletRequest request )
85      {
86          chantierControllerService.registerConverters( );
87          chantierControllerService.updateFromRequest( request );
88          int numDemande = formulaireService.getNumDemande( request );
89          demandeService.updateIsChantierStepSeen( numDemande, true );
90          fillLastUser( numDemande, request );
91          // Récupération de la redirection
92          String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
93          if ( StringUtils.isNullOrEmpty( nextStepPath ) )
94          {
95              return redirect( request, "../demandeOccupation.jsp" );
96          }
97          return redirect( request, nextStepPath );
98      }
99  
100     @Action( ACTION_ABANDON )
101     public String abandon( HttpServletRequest request )
102     {
103         formulaireService.removeFilesFromSession( request );
104         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
105         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
106         {
107             return redirect( request, "../demandeOccupation.jsp" );
108         }
109         return redirect( request, nextStepPath );
110     }
111 
112     private void fillModelForChantier( HttpServletRequest request, Map<String, Object> model )
113     {
114         chantierControllerService.initModel( model );
115         chantierControllerService.alimenterModel( request, model );
116         formulaireService.alimentationModelBO( request, model );
117         int numDemande = formulaireService.getNumDemande( request );
118         fillUserPossibleActions( request, model, numDemande );
119         model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
120         model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
121         model.put( "controlForm", true );
122     }
123 
124 }