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.ETAPE_DEMANDEUR;
37  import static fr.paris.lutece.plugins.ctv.constant.Document.JUSTIFICATIFS_CONVENTION;
38  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.MAX_FILE_SIZE;
39  
40  import java.util.Date;
41  import java.util.Map;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  import org.apache.commons.beanutils.ConvertUtils;
46  
47  import com.mysql.jdbc.StringUtils;
48  
49  import fr.paris.lutece.plugins.ctv.bo.DemandeWriting;
50  import fr.paris.lutece.plugins.ctv.bo.EntiteDemande;
51  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
52  import fr.paris.lutece.plugins.ctv.business.IEntiteDemandeService;
53  import fr.paris.lutece.plugins.ctv.constant.Document;
54  import fr.paris.lutece.plugins.ctv.converter.CustomDateConverter;
55  import fr.paris.lutece.plugins.ctv.converter.EnumConverter;
56  import fr.paris.lutece.plugins.ctv.handler.CtvUploadDemandeDocumentHandler;
57  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeOccupationBoServiceImpl;
58  import fr.paris.lutece.plugins.ctv.service.IEntiteControllerService;
59  import fr.paris.lutece.plugins.ctv.service.IFormulaireDemandeOccupationBoService;
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  @Controller( controllerJsp = "demandeur.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/occupation/etapes", right = "DEMANDE_OCCUPATION" )
66  public class DemandeurJspBean extends AbstractCtvJspBean
67  {
68  
69      private static final long serialVersionUID = -5935071488662220709L;
70  
71      // Service
72      private IEntiteControllerService entiteControllerService = SpringContextService.getBean( "entiteControllerService" );
73      protected IFormulaireDemandeOccupationBoService formulaireService = FormulaireDemandeOccupationBoServiceImpl.getInstance( );
74      protected IEntiteDemandeService entiteDemandeService = SpringContextService.getBean( "entiteDemandeService" );
75      
76      private static final String EXONERATION_DE_TAXE = "exonerationDeTaxe";
77      private static final CtvUploadDemandeDocumentHandler ctvDemandeUploadHandler = SpringContextService.getBean( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER );
78  
79      // Template
80      private static final String TEMPLATE_DEMANDEUR = "admin/plugins/ctv/etapes/demandeur.html";
81  
82      // Title
83      private static final String DEMANDEUR_TITLE = "ctv.etape.demandeur.title";
84  
85      private static final String VIEW_DEMANDEUR = "demandeur";
86  
87      @View( defaultView = true, value = VIEW_DEMANDEUR )
88      public String getDemandeurView( HttpServletRequest request )
89      {
90          Map<String, Object> model = getModel( );
91          int numDemande = formulaireService.getNumDemande( request );
92          fillUserPossibleActions( request, model, numDemande );
93          fillModelForDemandeur( request, model );
94          if ( request.getParameter( "complete" ) != null )
95          {
96              model.put( "controlForm", true );
97          }
98          return getPage( DEMANDEUR_TITLE, TEMPLATE_DEMANDEUR, model );
99      }
100 
101     @Action( ACTION_SAVE )
102     public String doSaveAction( HttpServletRequest request )
103     {
104         storeFiles( request );
105         EntiteDemande demandeur = new EntiteDemande( );
106         ConvertUtils.register( new EnumConverter( ), EntiteDemande.ProfilEntite.class );
107         ConvertUtils.register( new EnumConverter( ), EntiteDemande.Civilite.class );
108         ConvertUtils.register(new  CustomDateConverter(), Date.class );
109         populate( demandeur, request );
110         int numDemandeur = formulaireService.getNumDemande( request );
111         entiteDemandeService.updateDemandeur( numDemandeur, demandeur );
112         fillLastUser( numDemandeur, request );
113         DemandeWriting demande = new DemandeWriting();
114         ConvertUtils.register( new EnumConverter( ), DemandeWriting.ExonerationTaxe.class );
115         populate(demande, request);
116         // Récupération de la redirection
117         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
118         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
119         {
120             return redirect( request, "../demandeOccupation.jsp" );
121         }
122         return redirect( request, nextStepPath );
123     }
124 
125     @Action( ACTION_ABANDON )
126     public String abandon( HttpServletRequest request )
127     {
128         formulaireService.removeFilesFromSession( request );
129         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
130         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
131         {
132             return redirect( request, "../demandeOccupation.jsp" );
133         }
134         return redirect( request, nextStepPath );
135     }
136 
137     private void fillModelForDemandeur( HttpServletRequest request, Map<String, Object> model )
138     {
139         entiteControllerService.fillModelForEntite( request, model, ETAPE_DEMANDEUR );
140         formulaireService.sauvegardeEtape( request, model, ETAPE_DEMANDEUR );
141         formulaireService.alimentationModel( request, model );
142         formulaireService.alimentationModelBO( request, model );
143 
144         int numDemande = formulaireService.getNumDemande( request );
145         fillUserPossibleActions( request, model, numDemande );
146         model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
147         model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
148         model.put( "controlForm", true );
149         model.put( EXONERATION_DE_TAXE, DemandeWriting.ExonerationTaxe.values( ) );
150         model.put( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER, ctvDemandeUploadHandler );
151         model.put( MAX_FILE_SIZE, ctvDemandeUploadHandler.getMaxFileSize( ) );
152         model.put( Document.JUSTIFICATIFS_CONVENTION + "_listUploadedFiles", ctvDemandeUploadHandler.getListUploadedFiles(Document.JUSTIFICATIFS_CONVENTION, request.getSession( ) ) );
153     }
154     
155     private void storeFiles( HttpServletRequest request )
156     {
157         ctvDemandeUploadHandler.storeFilesOnDisk( request, JUSTIFICATIFS_CONVENTION );
158     }
159 
160 }