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 static fr.paris.lutece.plugins.ctv.constants.CtvConstants.VALIDER_TRANSFERT;
37  
38  import java.util.List;
39  import java.util.Map;
40  
41  import javax.servlet.http.HttpServletRequest;
42  
43  import com.mysql.jdbc.StringUtils;
44  
45  import fr.paris.lutece.plugins.ctv.bo.ChantierOccupation;
46  import fr.paris.lutece.plugins.ctv.bo.Emprise;
47  import fr.paris.lutece.plugins.ctv.bo.InfosSuperviseur;
48  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractSuperviseurJpsBean;
49  import fr.paris.lutece.plugins.ctv.business.IChantierService;
50  import fr.paris.lutece.plugins.ctv.business.IEmpriseService;
51  import fr.paris.lutece.plugins.ctv.constant.StatutDemande;
52  import fr.paris.lutece.plugins.ctv.constant.StatutEmprise;
53  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
54  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeOccupationBoServiceImpl;
55  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
56  import fr.paris.lutece.plugins.ctv.service.IFormulaireDemandeOccupationBoService;
57  import fr.paris.lutece.plugins.ctv.view.object.DemandeReading;
58  import fr.paris.lutece.plugins.unittree.service.unit.IUnitService;
59  import fr.paris.lutece.portal.service.spring.SpringContextService;
60  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
61  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
62  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
63  
64  //TODO : Refactoriser/Renommer lorsque l'étape de qualification sera définie
65  @Controller( controllerJsp = "superviseur.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/occupation/etapes", right = "DEMANDE_OCCUPATION" )
66  public class SuperviseurJspBean extends AbstractSuperviseurJpsBean
67  {
68  
69      private IFormulaire formulaireService = FormulaireDemandeOccupationBoServiceImpl.getInstance( );
70      private IFormulaireDemandeOccupationBoService formulaireServiceBo = FormulaireDemandeOccupationBoServiceImpl.getInstance( );
71      private static final IChantierService chantierService = SpringContextService.getBean( "chantierService" );
72      private static final long serialVersionUID = -5906084384644405383L;
73      private static final String ACTION_SAVE = "save";
74      private static final String ACTION_SAVE_STATUS = "save_status";
75      private static final String ACTION_QUICK_SIGNER = "quick_signer";
76      private IUnitService unitService = SpringContextService.getBean( IUnitService.BEAN_UNIT_SERVICE );
77      private IEmpriseService empriseService = SpringContextService.getBean( "empriseService" );
78      // Template
79      private static final String TEMPLATE_SUPERVISEUR = "admin/plugins/ctv/etapes/superviseur.html";
80      private static final String ACTION_RECUPERATION_DEMANDE = "recuperation_demande";
81  
82      @View( defaultView = true, value = VIEW_SUPERVISEUR )
83      public String getSuperviseurView( HttpServletRequest request )
84      {
85          Map<String, Object> model = initModel( request );
86          model.put( "sectors", unitService.findAllSectors( ) );
87          int numDemande = getFormulaireService( ).getNumDemande( request );
88          DemandeReading demande = demandeService.findByNumDemande( numDemande );
89          InfosSuperviseur oldInfosSuperviseur = infosSuperviseurService.findByNumDemande( numDemande );
90          ChantierOccupation chantierOccupation = chantierService.getChantierOccupationByNumDemande( numDemande );
91          model.put( "chantier", chantierOccupation );
92          model.put( "superviseur", oldInfosSuperviseur );
93          model.put( "demande", demande );
94          return getPage( SUPERVISEUR_TITLE, TEMPLATE_SUPERVISEUR, model );
95      }
96  
97      @Action( ACTION_SAVE )
98      public String saveInfoSup( HttpServletRequest request )
99      {
100         updateInfoSup( request );
101         storeQualificationFiles( request );
102         // Récupération de la redirection
103         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
104         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
105         {
106             return redirect( request, "../demandeOccupation.jsp" );
107         }
108         return redirect( request, nextStepPath );
109     }
110 
111     @Action( ACTION_QUICK_SIGNER )
112     public String doQuickSignerAction( HttpServletRequest request )
113     {
114         return doQuickSigner( request );
115     }
116 
117     @Action( ACTION_RECUPERATION_DEMANDE )
118     public String recuperationDemande( HttpServletRequest request )
119     {
120         int numDemande = getFormulaireService( ).getNumDemande( request );
121         demandeService.updateDemandeStatut( numDemande, StatutDemande.A_TRAITER );
122 
123         List<Emprise> listEmprises = empriseService.findEmprisesByDemandeId( numDemande );
124 
125         for ( Emprise emprise : listEmprises )
126         {
127             empriseService.updateStatut( emprise.getEmpriseId( ), StatutEmprise.A_TRAITER );
128         }
129 
130         demandeService.setLastInstructeur( getUser( ).getUserId( ), numDemande );
131 
132         return redirect( request, "superviseur.jsp" );
133     }
134 
135     @Action( ACTION_SAVE_STATUS )
136     public String doSaveAction( HttpServletRequest request )
137     {
138 
139         String redirection = doSave( request );
140         String statut = request.getParameter( PARAM_STATUT );
141         StatutDemande statutDemande = StatutDemande.valueOf( statut );
142         int numDemande = getFormulaireService( ).getNumDemande( request );
143         if ( statutDemande != null && statutDemande == StatutDemande.A_COMPLETER )
144         {
145             emailTask.sendEmail( CtvConstants.EMAIL_DEMANDE_RENVOI_DEMANDEUR, numDemande, getLocale( ), request, -1 );
146         }
147         return redirection;
148     }
149 
150     @Action( ACTION_ABANDON )
151     public String abandon( HttpServletRequest request )
152     {
153         formulaireServiceBo.removeFilesFromSession( request );
154         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
155         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
156         {
157             return redirect( request, "../demandeOccupation.jsp" );
158         }
159         return redirect( request, nextStepPath );
160     }
161 
162     @Override
163     protected IFormulaire getFormulaireService( )
164     {
165         return formulaireService;
166     }
167 
168     @Override
169     protected IFormulaireDemandeOccupationBoService getFormulaireServiceBo( )
170     {
171         return formulaireServiceBo;
172     }
173 
174     @Action( VALIDER_TRANSFERT )
175     public String validerTransfert( HttpServletRequest request )
176     {
177         return validateTransfertSecteur( request, "superviseur.jsp" );
178     }
179 
180 }