View Javadoc
1   /*
2    * Copyright (c) 2002-2018, Mairie de 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   	
35  
36  package fr.paris.lutece.plugins.accrochageff.web;
37   
38  import java.util.Map;
39  
40  import javax.servlet.http.HttpServletRequest;
41  
42  import fr.paris.lutece.plugins.accrochageff.business.FederationLinkHome;
43  import fr.paris.lutece.plugins.mylutece.modules.openam.service.OpenamService;
44  import fr.paris.lutece.portal.service.message.SiteMessage;
45  import fr.paris.lutece.portal.service.message.SiteMessageException;
46  import fr.paris.lutece.portal.service.message.SiteMessageService;
47  import fr.paris.lutece.portal.service.security.SecurityService;
48  import fr.paris.lutece.portal.service.util.AppPathService;
49  import fr.paris.lutece.portal.service.util.AppPropertiesService;
50  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
51  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
52  import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
53  import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
54  import fr.paris.lutece.portal.web.xpages.XPage;
55  import fr.paris.lutece.util.url.UrlItem; 
56  
57  /**
58   * This class provides the user interface to manage FederationLink xpages ( manage, create, modify, remove )
59   */
60  @Controller( xpageName = "federationlink" , pageTitleI18nKey = "accrochageff.xpage.federationlink.pageTitle" , pagePathI18nKey = "accrochageff.xpage.federationlink.pagePathLabel" )
61  public class FederationLinkXPage extends MVCApplication
62  {
63      // Templates
64      private static final String TEMPLATE_MANAGE_FEDERATIONLINKS="/skin/plugins/accrochageff/manage_federationlinks.html";
65     
66      //properties
67      
68      private static final String PROPERTY_OPEN_LINK_URL = "accrochageff.openLinkUrl";
69      private static final String PROPERTY_CREATE_LINk_URL = "accrochageff.createLinkUrl";
70      private static final String PROPERTY_REDIRECT_AFTER_DELETE_URL = "accrochageff.redirectAfterDeleteUrl";
71      
72          
73      
74      
75      // Parameters
76      private static final String PARAMETER_ID_FEDERATIONLINK = "id";
77      
78      // Markers
79      private static final String MARK_FEDERATIONLINK_LIST = "federationlink_list";
80      private static final String MARK_OPEN_LINK_URL = "open_link_url";
81      private static final String MARK_CREATE_LINK_URL = "create_link_url";
82      
83     // Message
84      private static final String MESSAGE_CONFIRM_REMOVE_FEDERATIONLINK = "accrochageff.message.confirmRemoveFederationLink";
85      
86      // Views
87      private static final String VIEW_MANAGE_FEDERATIONLINKS = "manageFederationLinks";
88   
89      // Actions
90       private static final String ACTION_REMOVE_FEDERATIONLINK = "removeFederationLink";
91      private static final String ACTION_CONFIRM_REMOVE_FEDERATIONLINK = "confirmRemoveFederationLink";
92  
93      // Infos
94      private static final String INFO_FEDERATIONLINK_REMOVED = "accrochageff.info.federationlink.removed";
95      
96      /**
97       * return the form to manage federationlinks
98       * @param request The Http request
99       * @return the html code of the list of federationlinks
100      */
101     @View( value = VIEW_MANAGE_FEDERATIONLINKS, defaultView = true )
102     public XPage getManageFederationLinks( HttpServletRequest request )
103     {
104         Map<String, Object> model = getModel(  );
105         String strCreateLinkUrl=AppPropertiesService.getProperty( PROPERTY_CREATE_LINk_URL );
106         String strOpenLinkUrl=AppPropertiesService.getProperty( PROPERTY_OPEN_LINK_URL);
107         
108         
109         String strToken=OpenamService.getInstance( ).getConnectionCookie( request );
110         model.put( MARK_FEDERATIONLINK_LIST, FederationLinkHome.getFederationLinkList( strToken ) );
111         model.put( MARK_OPEN_LINK_URL,strOpenLinkUrl );
112         model.put( MARK_CREATE_LINK_URL, strCreateLinkUrl );
113           
114         
115         XPage xpage =getXPage( TEMPLATE_MANAGE_FEDERATIONLINKS, request.getLocale(  ), model );
116         xpage.setStandalone( true );
117         return xpage;
118     }
119 
120   
121 
122     /**
123      * Manages the removal form of a federationlink whose identifier is in the http
124      * request
125      *
126      * @param request The Http request
127      * @return the html code to confirm
128      * @throws fr.paris.lutece.portal.service.message.SiteMessageException {@link fr.paris.lutece.portal.service.message.SiteMessageException}
129      */
130     @Action( ACTION_CONFIRM_REMOVE_FEDERATIONLINK )
131     public XPage getConfirmRemoveFederationLink( HttpServletRequest request ) throws SiteMessageException
132     {
133         String strId =  request.getParameter( PARAMETER_ID_FEDERATIONLINK ) ;
134 
135         UrlItem url = new UrlItem( getActionFullUrl(ACTION_REMOVE_FEDERATIONLINK ) );
136         url.addParameter( PARAMETER_ID_FEDERATIONLINK, strId );
137         
138         SiteMessageService.setMessage( request, MESSAGE_CONFIRM_REMOVE_FEDERATIONLINK, SiteMessage.TYPE_CONFIRMATION, url.getUrl(  ) );
139         return null;
140     }
141 
142     /**
143      * Handles the removal form of a federationlink
144      *
145      * @param request The Http request
146      * @return the jsp URL to display the form to manage federationlinks
147      */
148     @Action( ACTION_REMOVE_FEDERATIONLINK )
149     public XPage doRemoveFederationLink( HttpServletRequest request )
150     {
151         String strRedirectUrl= AppPathService.getBaseUrl( )+ AppPropertiesService.getProperty( PROPERTY_REDIRECT_AFTER_DELETE_URL );
152         String strId =  request.getParameter( PARAMETER_ID_FEDERATIONLINK  );
153         String strToken=OpenamService.getInstance( ).getConnectionCookie( request );
154         boolean bDelete = FederationLinkHome.deleteFederationLink( strId, strToken );
155    
156         return redirect( request, strRedirectUrl );
157     }
158 
159   
160 }