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.intention;
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.ChantierIntention;
45  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
46  import fr.paris.lutece.plugins.ctv.business.IChantierService;
47  import fr.paris.lutece.plugins.ctv.constant.TypeProfileCtv;
48  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
49  import fr.paris.lutece.plugins.ctv.service.ChantierIntentionControllerService;
50  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeIntentionServiceImpl;
51  import fr.paris.lutece.plugins.ctv.service.IChantierControllerService;
52  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
53  import fr.paris.lutece.portal.service.datastore.DatastoreService;
54  import fr.paris.lutece.portal.service.spring.SpringContextService;
55  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
56  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
57  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
58  
59  @Controller( controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/intention/etapes", controllerJsp = "chantier.jsp", right = "DEMANDE_INTENTION" )
60  public class ChantierJspBean extends AbstractCtvJspBean
61  {
62  
63      private static final long serialVersionUID = -3770916832486796996L;
64  
65      private IChantierControllerService chantierIntentionControllerService = ChantierIntentionControllerService.getInstance( );
66      protected IFormulaire formulaireIntentionService = FormulaireDemandeIntentionServiceImpl.getInstance( );
67      protected IChantierService chantierService = SpringContextService.getBean( "chantierService" );
68  
69      @View( value = ETAPE_CHANTIER, defaultView = true )
70      public String getChantier( HttpServletRequest request )
71      {
72  
73          Map<String, Object> model = getModel( );
74          chantierIntentionControllerService.initModel( model );
75          chantierIntentionControllerService.alimenterModel( request, model );
76          boolean isConcessionnaire = ctvProfileService.hasUserProfile( getUser( ), TypeProfileCtv.CONCESSIONNAIRE, getPlugin( ), request );
77          int numDemande = formulaireIntentionService.getNumDemande( request );
78          int toleranceBarrageUs = Integer.parseInt( DatastoreService.getDataValue( "parametre.tolerance.debut.chantier.barrage.us", "7" ) );
79          fillUserPossibleActions( request, model, numDemande );
80          model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
81          model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
82          model.put( "toleranceBarrageUs", toleranceBarrageUs );
83          model.put( "isConcessionnaire", isConcessionnaire );
84          checkingExistingErrors( request, model, numDemande );
85          return getPage( "", CtvConstants.TEMPLATE_CHANTIER_INTENTION, model );
86      }
87  
88      private void checkingExistingErrors( HttpServletRequest request, Map<String, Object> model, int numDemande )
89      {
90          ChantierIntention chantier = chantierService.getChantierIntentionByNumDemande( numDemande );
91          if ( ( request.getParameter( "complete" ) != null ) || ( chantier != null ) )
92          {
93              model.put( "controlForm", true );
94          }
95      }
96  
97      @Action( ACTION_SAVE )
98      public String save( HttpServletRequest request )
99      {
100         updateChantier( request );
101         int numDemande = formulaireIntentionService.getNumDemande( request );
102         fillLastUser( numDemande, request );
103         // Récupération de la redirection
104         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
105         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
106         {
107             return redirect( request, "chantier.jsp" );
108         }
109         return redirect( request, nextStepPath );
110 
111     }
112 
113     @Action( ACTION_NEXT )
114     public String next( HttpServletRequest request )
115     {
116         updateChantier( request );
117         return redirect( request, "emprises.jsp" );
118     }
119 
120     @Action( ACTION_COMPLETE_LATER )
121     public String completeLater( HttpServletRequest request )
122     {
123         updateChantier( request );
124         int numDemande = formulaireIntentionService.getNumDemande( request );
125         fillLastUser( numDemande, request );
126         formulaireIntentionService.removeFilesFromSession( request );
127         return redirect( request, getAbsolutePath( request, PATH_TABLEAU_DE_BORD ) );
128     }
129 
130     @Action( ACTION_ABANDON )
131     public String abandon( HttpServletRequest request )
132     {
133         formulaireIntentionService.removeFilesFromSession( request );
134         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
135         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
136         {
137             return redirect( request, "../demandeIntention.jsp" );
138         }
139         return redirect( request, nextStepPath );
140     }
141 
142     private void updateChantier( HttpServletRequest request )
143     {
144         int numDemande = formulaireIntentionService.getNumDemande( request );
145         demandeService.updateIsChantierStepSeen( numDemande, true );
146         chantierIntentionControllerService.registerConverters( );
147         chantierIntentionControllerService.updateFromRequest( request );
148     }
149 
150 }