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.DEMANDE;
37  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ETAPE_SUPERVISEUR;
38  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.NATURES_CHANTIER;
39  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.SESSION_NUM_DEMANDE_ID;
40  
41  import java.util.Map;
42  
43  import javax.servlet.http.HttpServletRequest;
44  
45  import fr.paris.lutece.plugins.ctv.bo.Conflit;
46  import fr.paris.lutece.plugins.ctv.bo.InfosSuperviseur;
47  import fr.paris.lutece.plugins.ctv.business.IConflitService;
48  import fr.paris.lutece.plugins.ctv.business.IDemandeService;
49  import fr.paris.lutece.plugins.ctv.business.IInfosSuperviseurService;
50  import fr.paris.lutece.plugins.ctv.business.IReferentielsService;
51  import fr.paris.lutece.plugins.ctv.view.object.DemandeReading;
52  import fr.paris.lutece.portal.business.user.AdminUser;
53  import fr.paris.lutece.portal.business.user.AdminUserHome;
54  import fr.paris.lutece.portal.service.spring.SpringContextService;
55  
56  public class FormulaireDemandeOccupationBoServiceImpl extends FormulaireDemandeOccupationServiceImpl implements IFormulaireDemandeOccupationBoService
57  {
58      public static final String LIBELLE_NATURE_CHANTIER = "libelleNatureChantier";
59  
60      private static final IDemandeService demandeService = SpringContextService.getBean( "demandeService" );
61  
62      private static final IConflitService conflitService = SpringContextService.getBean( "conflitService" );
63  
64      private static final IInfosSuperviseurService infosSuperviseurService = SpringContextService.getBean( "infosSuperviseurService" );
65  
66      private static IReferentielsService referentielsService = SpringContextService.getBean( "referentielsService" );
67  
68      private FormulaireDemandeOccupationBoServiceImpl( )
69      {
70          super( );
71      }
72  
73      public static final IFormulaireDemandeOccupationBoService formulaireDemandeOccupationService = new FormulaireDemandeOccupationBoServiceImpl( );
74  
75      public static IFormulaireDemandeOccupationBoService getInstance( )
76      {
77          return formulaireDemandeOccupationService;
78      }
79  
80      @Override
81      public void alimentationModelBO( HttpServletRequest request, Map<String, Object> model )
82      {
83  
84          int numDemande = 0;
85          if ( request.getParameter( "num_demande_projet" ) != null )
86          {
87              request.getSession( ).setAttribute( SESSION_NUM_DEMANDE_ID, request.getParameter( "num_demande_projet" ) );
88              numDemande = Integer.parseInt( String.valueOf( request.getSession( ).getAttribute( SESSION_NUM_DEMANDE_ID ) ) );
89          }
90          else
91              if ( model.get( SESSION_NUM_DEMANDE_ID ) != null )
92              {
93                  numDemande = (int) model.get( SESSION_NUM_DEMANDE_ID );
94              }
95              else
96              {
97                  numDemande = Integer.parseInt( String.valueOf( request.getSession( ).getAttribute( SESSION_NUM_DEMANDE_ID ) ) );
98              }
99  
100         // (Instruction)
101         DemandeReading demandeOccupation = demandeService.findByNumDemande( numDemande );
102 
103         if ( null != demandeOccupation )
104         {
105             Integer origineTransfertUserId = demandeOccupation.getDemandeOrigineTransfertUserId( );
106             if ( ( origineTransfertUserId != null ) && ( origineTransfertUserId > 0 ) )
107             {
108                 AdminUser origineTransfertUser = AdminUserHome.findByPrimaryKey( origineTransfertUserId );
109                 demandeOccupation.setDemandeOrigineTransfertUserPrenom( origineTransfertUser.getFirstName( ) );
110                 demandeOccupation.setDemandeOrigineTransfertUserNom( origineTransfertUser.getLastName( ) );
111             }
112             model.put( DEMANDE, demandeOccupation );
113             model.put( LIBELLE_NATURE_CHANTIER, chantierService.getNatureTravauxLibelleByNatureChantier( demandeOccupation.getChantierNature( ) ) );
114         }
115 
116         // Etape conflits
117         Conflit conflit = conflitService.findConflitByNumDemande( numDemande );
118         model.put( "recap_conflit", conflit != null );
119         InfosSuperviseur infosSuperviseur = infosSuperviseurService.findByNumDemande( numDemande );
120         model.put( ETAPE_SUPERVISEUR, infosSuperviseur );
121         model.put( NATURES_CHANTIER, referentielsService.getNatureTravauxOccupation( ) );
122         model.put( "numDemande", numDemande );
123     }
124 
125 }