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.controller.front;
35  
36  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_ABANDON;
37  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_COMPLETE_LATER;
38  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ACTION_SAVE;
39  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ETAPE_EMPRISE;
40  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.ETAPE_EXECUTANT_TRAVAUX;
41  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.PAGE_PORTAL;
42  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.PARAMETER_NEXT_STEP;
43  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.TEMPLATE_EXECUTANT_TRAVAUX;
44  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.XPAGE_ACCUEIL;
45  
46  import java.util.Map;
47  
48  import javax.servlet.http.HttpServletRequest;
49  
50  import org.apache.commons.lang3.StringUtils;
51  
52  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
53  import fr.paris.lutece.plugins.ctv.service.ExecutantControllerService;
54  import fr.paris.lutece.plugins.ctv.service.FormulaireDemandeOccupationServiceImpl;
55  import fr.paris.lutece.plugins.ctv.service.IExecutantControllerService;
56  import fr.paris.lutece.plugins.ctv.service.IFormulaire;
57  import fr.paris.lutece.plugins.ctv.util.Utils;
58  import fr.paris.lutece.portal.service.security.UserNotSignedException;
59  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
60  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
61  import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
62  import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
63  import fr.paris.lutece.portal.web.xpages.XPage;
64  
65  @Controller( xpageName = ETAPE_EXECUTANT_TRAVAUX )
66  public class ExecutantApp extends MVCApplication
67  {
68  
69      private IExecutantControllerService executantControllerService = ExecutantControllerService.getInstance( );
70      private IFormulaire formulaireService = FormulaireDemandeOccupationServiceImpl.getInstance( );
71  
72      @View( value = ETAPE_EXECUTANT_TRAVAUX, defaultView = true )
73      public XPage getExecutantTravaux( HttpServletRequest request ) throws UserNotSignedException
74      {
75          Utils.getUser( request );
76          Map<String, Object> model = getModel( );
77          executantControllerService.initModel( model );
78          executantControllerService.alimenterModel( request, model );
79          return getXPage( TEMPLATE_EXECUTANT_TRAVAUX, request.getLocale( ), model );
80      }
81  
82      @Action( CtvConstants.ACTION_NEXT )
83      public XPage nextPage( HttpServletRequest request )
84      {
85          executantControllerService.updateFromRequest( request );
86          return redirect( request, PAGE_PORTAL + ETAPE_EMPRISE );
87      }
88  
89      @Action( value = ACTION_COMPLETE_LATER )
90      public XPage completeLater( HttpServletRequest request )
91      {
92          executantControllerService.updateFromRequest( request );
93          return redirect( request, PAGE_PORTAL + XPAGE_ACCUEIL );
94      }
95  
96      @Action( ACTION_SAVE )
97      public XPage doSaveAction( HttpServletRequest request )
98      {
99          executantControllerService.updateFromRequest( request );
100         // Récupération de la redirection
101         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
102         if ( StringUtils.isAnyEmpty( nextStepPath ) )
103         {
104             return redirect( request, PAGE_PORTAL + XPAGE_ACCUEIL );
105         }
106         return redirect( request, PAGE_PORTAL + nextStepPath );
107     }
108 
109     @Action( ACTION_ABANDON )
110     public XPage doAbandonAction( HttpServletRequest request )
111     {
112         formulaireService.removeFilesFromSession( request );
113         // Récupération de la redirection
114         String nextStepPath = request.getParameter( PARAMETER_NEXT_STEP );
115         if ( StringUtils.isAnyEmpty( nextStepPath ) )
116         {
117             return redirect( request, PAGE_PORTAL + XPAGE_ACCUEIL );
118         }
119         return redirect( request, PAGE_PORTAL + nextStepPath );
120     }
121 
122 }