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.constant.Document.AUTRES_DOCUMENTS;
37  import static fr.paris.lutece.plugins.ctv.constant.Document.CROQUIS;
38  import static fr.paris.lutece.plugins.ctv.constant.Document.ETAT_DES_LIEUX;
39  import static fr.paris.lutece.plugins.ctv.constant.Document.JUSTIFICATIFS_URBANISME;
40  import static fr.paris.lutece.plugins.ctv.constant.Document.JUSTIFICATIF_IMPOSSIBILITE_USAGE_LOCAUX;
41  import static fr.paris.lutece.plugins.ctv.constant.Document.NOTE_CALCUL;
42  import static fr.paris.lutece.plugins.ctv.constant.Document.PLAN_COMPLEMENTAIRE;
43  import static fr.paris.lutece.plugins.ctv.constant.Document.PLAN_DETAILS;
44  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ETAPE_DOCUMENTS_JOINTS;
45  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.MAX_FILE_SIZE;
46  
47  import java.util.Map;
48  
49  import javax.servlet.http.HttpServletRequest;
50  
51  import com.mysql.jdbc.StringUtils;
52  
53  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
54  import fr.paris.lutece.plugins.ctv.handler.CtvUploadDemandeDocumentHandler;
55  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeOccupationBoServiceImpl;
56  import fr.paris.lutece.plugins.ctv.service.IFormulaireDemandeOccupationBoService;
57  import fr.paris.lutece.portal.service.spring.SpringContextService;
58  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
59  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
60  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
61  
62  @Controller( controllerJsp = "documents.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/occupation/etapes", right = "DEMANDE_OCCUPATION" )
63  public class DocumentsJspBean extends AbstractCtvJspBean
64  {
65  
66      private static final long serialVersionUID = -401795214233432762L;
67  
68      // Template
69      private static final String TEMPLATE_DOCUMENTS = "admin/plugins/ctv/etapes/documentsJoints.html";
70  
71      // Title
72      private static final String DOCUMENTS_TITLE = "ctv.etape.documents.title";
73  
74      private static final String VIEW_DOCUMENTS = "documents";
75  
76      protected CtvUploadDemandeDocumentHandler ctvDemandeUploadHandler = SpringContextService
77              .getBean( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER );
78      protected IFormulaireDemandeOccupationBoService formulaireService = FormulaireDemandeOccupationBoServiceImpl.getInstance( );
79  
80      @View( defaultView = true, value = VIEW_DOCUMENTS )
81      public String getExecutantView( HttpServletRequest request )
82      {
83          Map<String, Object> model = getModel( );
84          initModel( request, model );
85          return getPage( DOCUMENTS_TITLE, TEMPLATE_DOCUMENTS, model );
86      }
87  
88      @Action( ACTION_SAVE )
89      public String next( HttpServletRequest request )
90      {
91          storeFiles( request );
92          int numDemande = formulaireService.getNumDemande( request );
93          fillLastUser( numDemande, request );
94          String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
95          if ( StringUtils.isNullOrEmpty( nextStepPath ) )
96          {
97              return redirect( request, "../demandeOccupation.jsp" );
98          }
99          else
100         {
101             return redirect( request, nextStepPath );
102         }
103 
104     }
105 
106     @Action( ACTION_ABANDON )
107     public String abandon( HttpServletRequest request )
108     {
109         formulaireService.removeFilesFromSession( request );
110         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
111         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
112         {
113             return redirect( request, "../demandeOccupation.jsp" );
114         }
115         return redirect( request, nextStepPath );
116     }
117 
118     private void initModel( HttpServletRequest request, Map<String, Object> model )
119     {
120         formulaireService.alimentationModel( request, model );
121         formulaireService.alimentationModelBO( request, model );
122         formulaireService.sauvegardeEtape( request, model, ETAPE_DOCUMENTS_JOINTS );
123         int numDemande = formulaireService.getNumDemande( request );
124         fillUserPossibleActions( request, model, numDemande );
125         model.put( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER, ctvDemandeUploadHandler );
126         model.put( MAX_FILE_SIZE, ctvDemandeUploadHandler.getMaxFileSize( ) );
127         model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
128         model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
129         model.put( "controlForm", true );
130     }
131 
132     private void storeFiles( HttpServletRequest request )
133     {
134         ctvDemandeUploadHandler.storeFilesOnDisk( request, JUSTIFICATIFS_URBANISME );
135         ctvDemandeUploadHandler.storeFilesOnDisk( request, ETAT_DES_LIEUX );
136         ctvDemandeUploadHandler.storeFilesOnDisk( request, PLAN_COMPLEMENTAIRE );
137         ctvDemandeUploadHandler.storeFilesOnDisk( request, CROQUIS );
138         ctvDemandeUploadHandler.storeFilesOnDisk( request, PLAN_DETAILS );
139         ctvDemandeUploadHandler.storeFilesOnDisk( request, NOTE_CALCUL );
140         ctvDemandeUploadHandler.storeFilesOnDisk( request, JUSTIFICATIF_IMPOSSIBILITE_USAGE_LOCAUX );
141         ctvDemandeUploadHandler.storeFilesOnDisk( request, AUTRES_DOCUMENTS );
142     }
143 
144 }