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.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.constant.Document.PLAN_EXPLOITATION;
45  import static fr.paris.lutece.plugins.ctv.constant.Document.PLAN_SITUATION;
46  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ETAPE_DOCUMENTS_JOINTS;
47  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.MAX_FILE_SIZE;
48  
49  import java.util.Map;
50  
51  import javax.servlet.http.HttpServletRequest;
52  import javax.servlet.http.HttpSession;
53  
54  import com.mysql.jdbc.StringUtils;
55  
56  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
57  import fr.paris.lutece.plugins.ctv.handler.CtvUploadDemandeDocumentHandler;
58  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeInterventionServiceImpl;
59  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
60  import fr.paris.lutece.plugins.ctv.view.object.DemandeReading;
61  import fr.paris.lutece.portal.service.spring.SpringContextService;
62  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
63  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
64  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
65  
66  @Controller( controllerJsp = "documents.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionDemandes/intervention/etapes", right = "TABLEAU_DE_BORD" )
67  public class DocumentsJspBean extends AbstractCtvJspBean
68  {
69  
70      private static final String INIT_FILES_NUMBER = "initFilesNumber";
71  
72      private static final long serialVersionUID = -401795214233432762L;
73  
74      // Template
75      private static final String TEMPLATE_DOCUMENTS = "admin/plugins/ctv/demandeIntervention/etapesIntervention/documentsJoints.html";
76  
77      // Title
78      private static final String DOCUMENTS_TITLE = "ctv.etape.documents.title";
79  
80      private static final String VIEW_DOCUMENTS = "documents";
81  
82      protected CtvUploadDemandeDocumentHandler ctvDemandeUploadHandler = SpringContextService
83              .getBean( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER );
84  
85      protected IFormulaire formulaireService = FormulaireDemandeInterventionServiceImpl.getInstance( );
86  
87      @View( defaultView = true, value = VIEW_DOCUMENTS )
88      public String getExecutantView( HttpServletRequest request )
89      {
90          Map<String, Object> model = getModel( );
91          initModel( request, model );
92          int numDemande = formulaireService.getNumDemande( request );
93          checkingExistingErrors( request, model, numDemande );
94          fillUserPossibleActions( request, model, numDemande );
95          HttpSession session = request.getSession( );
96          session.setAttribute( INIT_FILES_NUMBER, ctvDemandeUploadHandler.getFilesNumber( request ) );
97          return getPage( DOCUMENTS_TITLE, TEMPLATE_DOCUMENTS, model );
98      }
99  
100     @Action( ACTION_NEXT )
101     public String next( HttpServletRequest request )
102     {
103         storeFiles( request );
104         HttpSession session = request.getSession( );
105         int initFilesNumber = (int) session.getAttribute( INIT_FILES_NUMBER );
106         int actualFilesNumber = ctvDemandeUploadHandler.getFilesNumber( request );
107         if ( initFilesNumber != actualFilesNumber )
108         {
109             int numDemande = formulaireService.getNumDemande( request );
110             fillLastUser( numDemande, request );
111         }
112         return redirect( request, "validation.jsp" );
113     }
114 
115     @Action( ACTION_SAVE )
116     public String save( HttpServletRequest request )
117     {
118         storeFiles( request );
119         int numDemande = formulaireService.getNumDemande( request );
120         fillLastUser( numDemande, request );
121         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
122         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
123         {
124             return redirect( request, "../demandeIntervention.jsp" );
125         }
126         else
127         {
128             return redirect( request, nextStepPath );
129         }
130 
131     }
132 
133     @Action( ACTION_ABANDON )
134     public String abandon( HttpServletRequest request )
135     {
136         formulaireService.removeFilesFromSession( request );
137         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
138         if ( StringUtils.isNullOrEmpty( nextStepPath ) )
139         {
140             return redirect( request, "../demandeIntervention.jsp" );
141         }
142         return redirect( request, nextStepPath );
143     }
144 
145     @Action( ACTION_COMPLETE_LATER )
146     public String completeLater( HttpServletRequest request )
147     {
148         storeFiles( request );
149         formulaireService.removeFilesFromSession( request );
150         return redirect( request, getAbsolutePath( request, PATH_TABLEAU_DE_BORD ) );
151     }
152 
153     private void initModel( HttpServletRequest request, Map<String, Object> model )
154     {
155         formulaireService.alimentationModel( request, model );
156         formulaireService.sauvegardeEtape( request, model, ETAPE_DOCUMENTS_JOINTS );
157         model.put( CtvUploadDemandeDocumentHandler.CTV_DEMANDE_UPLOAD_HANDLER, ctvDemandeUploadHandler );
158         model.put( MAX_FILE_SIZE, ctvDemandeUploadHandler.getMaxFileSize( ) );
159         model.put( MARK_PATH_TABLEAU_DE_BORD, PATH_TABLEAU_DE_BORD );
160         model.put( MARK_PAGE_TITLE, TABLEAU_BORD_PAGE_TITLE );
161         String complete = request.getParameter( "complete" );
162         model.put( "controlForm", Boolean.parseBoolean( complete ) );
163     }
164 
165     private void storeFiles( HttpServletRequest request )
166     {
167         demandeService.updateIsDocumentStepSeen( formulaireService.getNumDemande( request ), true );
168         ctvDemandeUploadHandler.storeFilesOnDisk( request, JUSTIFICATIFS_URBANISME );
169         ctvDemandeUploadHandler.storeFilesOnDisk( request, ETAT_DES_LIEUX );
170         ctvDemandeUploadHandler.storeFilesOnDisk( request, PLAN_EXPLOITATION );
171         ctvDemandeUploadHandler.storeFilesOnDisk( request, PLAN_SITUATION );
172         ctvDemandeUploadHandler.storeFilesOnDisk( request, PLAN_COMPLEMENTAIRE );
173         ctvDemandeUploadHandler.storeFilesOnDisk( request, CROQUIS );
174         ctvDemandeUploadHandler.storeFilesOnDisk( request, PLAN_DETAILS );
175         ctvDemandeUploadHandler.storeFilesOnDisk( request, NOTE_CALCUL );
176         ctvDemandeUploadHandler.storeFilesOnDisk( request, JUSTIFICATIF_IMPOSSIBILITE_USAGE_LOCAUX );
177         ctvDemandeUploadHandler.storeFilesOnDisk( request, AUTRES_DOCUMENTS );
178     }
179 
180     private void checkingExistingErrors( HttpServletRequest request, Map<String, Object> model, int numDemande )
181     {
182         DemandeReading maDemande = demandeService.findByNumDemande( numDemande );
183         if ( request.getParameter( "complete" ) != null || maDemande.isDemandeIsDocumentStepSeen( ) )
184         {
185             model.put( "controlForm", true );
186         }
187     }
188 
189 }