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.service;
35  
36  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.EMPRISE_ID;
37  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.NEW_EMPRISE;
38  
39  import java.util.ArrayList;
40  import java.util.Date;
41  import java.util.List;
42  import java.util.Map;
43  
44  import javax.servlet.http.HttpServletRequest;
45  
46  import fr.paris.lutece.plugins.ctv.bo.ChantierIntention;
47  import fr.paris.lutece.plugins.ctv.bo.DetailsEmprise;
48  import fr.paris.lutece.plugins.ctv.bo.DetailsEmprise.TypeConfigurationSpecifique;
49  import fr.paris.lutece.plugins.ctv.bo.Emprise;
50  import fr.paris.lutece.plugins.ctv.business.IChantierService;
51  import fr.paris.lutece.plugins.ctv.business.IStockageImageService;
52  import fr.paris.lutece.plugins.ctv.constant.StatutEmprise;
53  import fr.paris.lutece.plugins.ctv.util.EmpriseMappingUtils;
54  import fr.paris.lutece.portal.service.datastore.DatastoreService;
55  import fr.paris.lutece.portal.service.spring.SpringContextService;
56  import fr.paris.lutece.portal.service.util.AppPropertiesService;
57  import fr.paris.lutece.util.bean.BeanUtil;
58  
59  public class EmpriseIntentionControllerService extends AbstractEmpriseControllerService
60  {
61  
62      private static String PATH_FOLDER_IMAGE_EMPRISE = AppPropertiesService.getProperty( "ctv.directory.upload" );
63      private static final IFormulaire formulaireService = FormulaireDemandeIntentionServiceImpl.getInstance( );
64      private static final IEmpriseControllerService empriseCtrlService = new EmpriseIntentionControllerService( );
65      private static final IChantierService chantierService = SpringContextService.getBean( "chantierService" );
66      private static final IStockageImageService stockageService = SpringContextService.getBean( "stockageImageService" );
67  
68      public static IEmpriseControllerService getInstance( )
69      {
70          return empriseCtrlService;
71      }
72  
73      @Override
74      public IFormulaire getFormulaireService( )
75      {
76          return formulaireService;
77      }
78  
79      @Override
80      public void updateEmpriseFromRequest( HttpServletRequest request, boolean withGeometry )
81      {
82          registerConverters( );
83          Emprise emprise = new Emprise( );
84          BeanUtil.populate( emprise, request );
85          int empriseId = getCurrentEmpriseId( request );
86          if ( empriseId > 0 )
87          {
88              List<Integer> selectedEmpriseIds = new ArrayList<Integer>( );
89              selectedEmpriseIds.add( empriseId );
90              empriseService.controlStatutEmpriseACoordoner( selectedEmpriseIds, emprise );
91              super.updateEmpriseFromRequest( request, withGeometry );
92          }
93      }
94  
95      @Override
96      public void initModel( Map<String, Object> model, HttpServletRequest request )
97      {
98          super.initModel( model, request );
99          initSpecificModel( model );
100 
101         int numDemande = formulaireService.getNumDemande( request );
102 
103         ChantierIntention chantier = chantierService.getChantierIntentionByNumDemande( numDemande );
104 
105         Emprise emprise = new Emprise( );
106         if ( chantier != null )
107         {
108             emprise.setEmpriseDateDebut( chantier.getChantierStartDate( ) );
109             emprise.setEmpriseDateFin( chantier.getChantierEndDate( ) );
110             emprise.setEmpriseAdresseDebut( chantier.getChantierAdresse( ) );
111         }
112 
113         model.put( "emprise", emprise );
114     }
115 
116     @Override
117     public void populateEmprise( HttpServletRequest request )
118     {
119         registerConverters( );
120         Emprise emprise = new Emprise( );
121         BeanUtil.populate( emprise, request );
122 
123         emprise.setEmpriseStatut( StatutEmprise.BROUILLON );
124         emprise.setEmpriseVueEnConference( "NON" );
125         emprise.setEmpriseTransforme( "NON" );
126 
127         populateGeometry( request, emprise );
128 
129         int empriseId = empriseService.createEmpriseIntention( formulaireService.getNumDemande( request ), emprise );
130 
131         // Fait 71985 enregistrer l'apercu sur le serveur
132         // Attention EmpriseDAO m├ęthode mapEmpriseCommon enregistre null en base pour map_preview_data_url
133         String pathFile = PATH_FOLDER_IMAGE_EMPRISE;
134         stockageService.saveImageOnServer( emprise.getMapPreviewDataUrl( ), new Date( ), pathFile, empriseId );
135 
136         DetailsEmprise details = new DetailsEmprise( );
137         EmpriseMappingUtils.map( request, details );
138         details.prepare( );
139         details.getConfigurationsSpecifiques( ).add( TypeConfigurationSpecifique.EMPRISE_MODIFIANT_SOL );
140         int paramDelaiDateGel = Integer.parseInt( DatastoreService.getDataValue( "parametre.numeric.intervention.duree.periode.gel", "0" ) );
141         empriseService.createDetails( empriseId, details, paramDelaiDateGel );
142         request.getSession( ).setAttribute( EMPRISE_ID, empriseId );
143         request.getSession( ).setAttribute( NEW_EMPRISE, true );
144     }
145 
146 }