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.conference.coordination;
35  
36  import static fr.paris.lutece.plugins.ctv.constants.CtvConstants.MAX_FILE_SIZE;
37  
38  import java.util.Date;
39  import java.util.HashMap;
40  import java.util.List;
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.ConferenceCoordination;
48  import fr.paris.lutece.plugins.ctv.bo.controller.demandes.AbstractCtvJspBean;
49  import fr.paris.lutece.plugins.ctv.business.IConferenceCoordinationService;
50  import fr.paris.lutece.plugins.ctv.constant.TypeProfileCtv;
51  import fr.paris.lutece.plugins.ctv.constants.CtvConstants;
52  import fr.paris.lutece.plugins.ctv.handler.CtvUploadConferenceCoordinationDocumentHandler;
53  import fr.paris.lutece.plugins.ctv.util.UnitTreeUtils;
54  import fr.paris.lutece.plugins.unittree.business.unit.Unit;
55  import fr.paris.lutece.plugins.unittree.service.unit.IUnitService;
56  import fr.paris.lutece.portal.business.user.AdminUser;
57  import fr.paris.lutece.portal.service.spring.SpringContextService;
58  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
59  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
60  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
61  
62  @Controller( controllerPath = "jsp/admin/plugins/ctv/conferenceCoordination", controllerJsp = "gestionConferenceCoordination.jsp", right = "GESTION_LISTE_CONFERENCE_COORDINATION" )
63  public class GestionConferenceCoordinationJspBean extends AbstractCtvJspBean
64  {
65  
66      private static final long serialVersionUID = 1L;
67      private IConferenceCoordinationService conferenceService = SpringContextService.getBean( "conferenceCoordinationService" );
68      private static final CtvUploadConferenceCoordinationDocumentHandler ctvConferenceCoordinationUploadHandler = SpringContextService
69              .getBean( CtvUploadConferenceCoordinationDocumentHandler.CTV_CONFERENCE_COORDINATION_UPLOAD_HANDLER );
70  
71      private IUnitService unitService = SpringContextService.getBean( IUnitService.BEAN_UNIT_SERVICE );
72  
73      @View( defaultView = true, value = VIEW_LIST_CONFERENCE_COORDINATION )
74      public String getListeConferenceCoordination( HttpServletRequest request )
75      {
76  
77          Map<String, Object> model = getModel( );
78  
79          AdminUser user = getUser( );
80          boolean isConcessionnaire = ctvProfileService.hasUserProfile( user, TypeProfileCtv.CONCESSIONNAIRE, getPlugin( ), request );
81          boolean isSuperviseur1 = ctvProfileService.hasUserProfile( user, TypeProfileCtv.SUPERVISEUR_1, getPlugin( ), request );
82          boolean isSuperviseur2 = ctvProfileService.hasUserProfile( user, TypeProfileCtv.SUPERVISEUR_2, getPlugin( ), request );
83          boolean isInstructeur = ctvProfileService.hasUserProfile( user, TypeProfileCtv.INSTRUCTEUR, getPlugin( ), request );
84  
85          if ( isSuperviseur1 || isSuperviseur2 )
86          {
87              model.put( "typeUser", TypeProfileCtv.SUPERVISEUR_1.name( ) );
88          }
89          else
90              if ( isConcessionnaire )
91              {
92                  model.put( "typeUser", TypeProfileCtv.CONCESSIONNAIRE.name( ) );
93              }
94              else
95                  if ( isInstructeur )
96                  {
97                      model.put( "typeUser", TypeProfileCtv.INSTRUCTEUR.name( ) );
98                  }
99  
100         ctvConferenceCoordinationUploadHandler.removeFilesInSession( request );
101         List<ConferenceCoordination> listConference = conferenceService.findAll( );
102         Map<String, List<FileItem>> conferenceDocument = new HashMap<>( );
103         for ( ConferenceCoordination conferenceCoordination : listConference )
104         {
105             Unit unit = unitService.getUnit( conferenceCoordination.getIdUniteOrga( ), false );
106             conferenceCoordination.setLabelUniteOrga( unit.getLabel( ) );
107             request.getSession( ).setAttribute( CtvConstants.SESSION_CONFERENCE_ID, conferenceCoordination.getId( ) );
108             ctvConferenceCoordinationUploadHandler.removeFilesInSession( request );
109             conferenceDocument.put( Integer.toString( conferenceCoordination.getId( ) ),
110                     ctvConferenceCoordinationUploadHandler.getListUploadedFiles( "conferenceDocument", request.getSession( ) ) );
111         }
112         model.put( "listConference", listConference );
113         model.put( "conferenceDocument", conferenceDocument );
114         return getPage( "", TEMPLATE_LIST_CONFERENCE_COORDINATION, model );
115     }
116 
117     @View( "editionConference" )
118     public String getEditionView( HttpServletRequest request )
119     {
120         Map<String, Object> model = getModel( );
121 
122         AdminUser user = getUser( );
123         boolean isSuperviseur1 = ctvProfileService.hasUserProfile( user, TypeProfileCtv.SUPERVISEUR_1, getPlugin( ), request );
124         boolean isSuperviseur2 = ctvProfileService.hasUserProfile( user, TypeProfileCtv.SUPERVISEUR_2, getPlugin( ), request );
125 
126         boolean isSuperviseur = isSuperviseur1 || isSuperviseur2;
127         model.put( "isSuperviseur", isSuperviseur );
128 
129         List<Unit> allUnits = unitService.getAllUnits( true );
130         String conferenceIdParam = request.getParameter( "conferenceId" );
131         if ( conferenceIdParam != null )
132         {
133             int conferenceId = Integer.parseInt( conferenceIdParam );
134             ConferenceCoordination conference = conferenceService.findConferenceCoordination( conferenceId );
135             model.put( "conference", conference );
136             model.put( "action", "modify" );
137             model.put( "liste_unite", UnitTreeUtils.getUnitTreeJson( allUnits, isSuperviseur, conference.getIdUniteOrga( ) ) );
138             request.getSession( ).setAttribute( CtvConstants.SESSION_CONFERENCE_ID, conferenceId );
139             ctvConferenceCoordinationUploadHandler.removeFilesInSession( request );
140         }
141         else
142         {
143             model.put( "action", "creation" );
144             model.put( "liste_unite", UnitTreeUtils.getUnitTreeJson( allUnits ) );
145             request.getSession( ).setAttribute( CtvConstants.SESSION_CONFERENCE_ID, CtvConstants.SESSION_CONFERENCE_ID );
146             ctvConferenceCoordinationUploadHandler.removeFilesInSession( request );
147         }
148         model.put( CtvUploadConferenceCoordinationDocumentHandler.CTV_CONFERENCE_COORDINATION_UPLOAD_HANDLER, ctvConferenceCoordinationUploadHandler );
149         model.put( MAX_FILE_SIZE, ctvConferenceCoordinationUploadHandler.getMaxFileSize( ) );
150         model.put( "conferenceDocument_listUploadedFiles",
151                 ctvConferenceCoordinationUploadHandler.getListUploadedFiles( "conferenceDocument", request.getSession( ) ) );
152         return getPage( "", TEMPLATE_MANAGE_CONFERENCE_COORDINATION, model );
153     }
154 
155     @Action( "creation" )
156     public String doCreationConference( HttpServletRequest request )
157     {
158         ConferenceCoordination conf = populateConferenceCoordination( request );
159         conf.setDateCreation( new Date( ) );
160         int conferenceId = conferenceService.insertConferenceCoordination( conf );
161         request.getSession( ).setAttribute( CtvConstants.SESSION_CONFERENCE_ID, conferenceId );
162         ctvConferenceCoordinationUploadHandler.storeFilesOnDisk( request, "conferenceDocument" );
163         return redirectView( request, VIEW_LIST_CONFERENCE_COORDINATION );
164     }
165 
166     @Action( "modify" )
167     public String doModifyConference( HttpServletRequest request )
168     {
169         ConferenceCoordination conf = populateConferenceCoordination( request );
170         conferenceService.updateConferenceCoordination( conf );
171         ctvConferenceCoordinationUploadHandler.storeFilesOnDisk( request, "conferenceDocument" );
172         return redirectView( request, VIEW_LIST_CONFERENCE_COORDINATION );
173     }
174 
175     @Action( "remove" )
176     public String remove( HttpServletRequest request )
177     {
178         int conferenceId = Integer.parseInt( request.getParameter( "conferenceId" ) );
179         if ( conferenceId > 0 )
180         {
181             conferenceService.deleteConference( conferenceId );
182             ctvConferenceCoordinationUploadHandler.removeFilesInSession( request );
183             ctvConferenceCoordinationUploadHandler.removeFilesItem( "conferenceDocument", request.getSession( ) );
184         }
185         return redirectView( request, VIEW_LIST_CONFERENCE_COORDINATION );
186     }
187 
188     private ConferenceCoordination populateConferenceCoordination( HttpServletRequest request )
189     {
190         ConferenceCoordination conf = new ConferenceCoordination( );
191         populate( conf, request );
192         return conf;
193     }
194 
195 }