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;
35  
36  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_DOWNLOAD;
37  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.NOM_FICHIER;
38  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.TEMPLATE_CONSULTATION_CR_VISITE;
39  
40  import java.util.HashMap;
41  import java.util.Map;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  import org.apache.commons.fileupload.FileItem;
46  
47  import fr.paris.lutece.plugins.ctv.bo.CompteRenduVisite;
48  import fr.paris.lutece.plugins.ctv.bo.ItemReferentiel.TypeReferentiel;
49  import fr.paris.lutece.plugins.ctv.business.ICompteRenduVisiteService;
50  import fr.paris.lutece.plugins.ctv.business.IDemandeService;
51  import fr.paris.lutece.plugins.ctv.business.IReferentielsService;
52  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
53  import fr.paris.lutece.plugins.ctv.handler.CtvUploadCompteRenduVisiteHandler;
54  import fr.paris.lutece.portal.service.spring.SpringContextService;
55  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
56  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
57  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
58  
59  @Controller( controllerJsp = "consultationnCompteRenduVisite.jsp", controllerPath = "jsp/admin/plugins/ctv/gestionCompteRenduVisites", right = "TABLEAU_DE_BORD" )
60  public class ConsultationCRVisiteJspBean extends AbstractCtvJspBean
61  {
62  
63      private static final String CR_VISITE_FILE_TYPE = "compteRenduVisite";
64  
65      private static final String CONSULTATION_CR_VISITE = "consultation_cr_visite";
66  
67      private CtvUploadCompteRenduVisiteHandler ctvUploadCompteRenduVisiteHandler = SpringContextService
68              .getBean( CtvUploadCompteRenduVisiteHandler.CTV_CR_VISITE_UPLOAD_HANDLER );
69  
70      private static ICompteRenduVisiteService compteRenduVisiteService = SpringContextService.getBean( "compteRenduVisiteService" );
71  
72      private static IReferentielsService referentielsService = SpringContextService.getBean( "referentielsService" );
73  
74      private static IDemandeService demandeService = SpringContextService.getBean( "demandeService" );
75  
76      @View( value = CONSULTATION_CR_VISITE, defaultView = true )
77      public String getConsultationCRVisite( HttpServletRequest request )
78      {
79          Map<String, Object> model = new HashMap<>( );
80          model.put( "types_visite", referentielsService.getItemReferentielList( TypeReferentiel.TYPE_VISITE ) );
81          String numProjet = request.getParameter( "num_projet" );
82          model.put( "num_projet", numProjet );
83          String numDemande = request.getParameter( "num_demande" );
84          model.put( "num_demande", numDemande );
85          String id = request.getParameter( "id" );
86          ctvUploadCompteRenduVisiteHandler.removeFilesInSession( request );
87          request.getSession( ).setAttribute( CtvConstants.SESSION_CR_VISITE_ID, id );
88          model.put( "compteRenduVisite_listUploadedFiles",
89                  ctvUploadCompteRenduVisiteHandler.getListUploadedFiles( CR_VISITE_FILE_TYPE, request.getSession( ) ) );
90          request.getSession( ).removeAttribute( CtvConstants.SESSION_CR_VISITE_ID );
91          CompteRenduVisite compteRenduVisite = compteRenduVisiteService.findCompteRenduVisite( Integer.parseInt( id ) );
92          model.put( CR_VISITE_FILE_TYPE, compteRenduVisite );
93          fillInfosFilDArianeProjet( model, numProjet );
94  
95          model.put( "demande", demandeService.findByNumDemande( Integer.parseInt( numDemande ) ) );
96  
97          return getPage( "", TEMPLATE_CONSULTATION_CR_VISITE, model );
98      }
99  
100     @Action( ACTION_DOWNLOAD )
101     public String download( HttpServletRequest request )
102     {
103         String id = request.getParameter( "id" );
104         request.getSession( ).setAttribute( CtvConstants.SESSION_CR_VISITE_ID, id );
105         FileItem fileItem = ctvUploadCompteRenduVisiteHandler.getFileItemByName( request, CR_VISITE_FILE_TYPE, request.getParameter( NOM_FICHIER ) );
106         request.getSession( ).removeAttribute( CtvConstants.SESSION_CR_VISITE_ID );
107         if ( fileItem != null )
108         {
109             download( fileItem.get( ), fileItem.getName( ), fileItem.getContentType( ) );
110         }
111         return redirectView( request, CONSULTATION_CR_VISITE );
112     }
113 
114     @Action( "retour" )
115     public String retour( HttpServletRequest request )
116     {
117         ctvUploadCompteRenduVisiteHandler.removeFilesInSession( request );
118         return redirectToProjet( request );
119     }
120 
121     private String redirectToProjet( HttpServletRequest request )
122     {
123         String numProjet = request.getParameter( "num_projet" );
124         String numDemande = request.getParameter( "num_demande" );
125         return redirect( request, getAbsolutePath( request, PATH_PAGE_PROJET ) + "?num_projet=" + numProjet + "&selected_demande_id=" + numDemande );
126     }
127 
128 }