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