View Javadoc
1   /*
2    * Copyright (c) 2002-2014, 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  package fr.paris.lutece.plugins.crm.web.portlet;
35  
36  import java.util.HashMap;
37  
38  import javax.servlet.http.HttpServletRequest;
39  
40  import fr.paris.lutece.plugins.crm.business.portlet.DemandTypePortlet;
41  import fr.paris.lutece.plugins.crm.business.portlet.DemandTypePortletHome;
42  import fr.paris.lutece.plugins.crm.service.category.CategoryService;
43  import fr.paris.lutece.plugins.crm.util.CrmUtils;
44  import fr.paris.lutece.plugins.crm.util.constants.CRMConstants;
45  import fr.paris.lutece.portal.business.portlet.PortletHome;
46  import fr.paris.lutece.portal.web.portlet.PortletJspBean;
47  import fr.paris.lutece.util.html.HtmlTemplate;
48  
49  /**
50   * This class provides the user interface to manage DemandTypePortletJspBean Portlet
51   */
52  public class DemandTypePortletJspBean extends PortletJspBean
53  {
54      // //////////////////////////////////////////////////////////////////////////
55      // Constants
56      private CategoryService _categoryService = CategoryService.getService( );
57  
58      /**
59       * {@inheritDoc}
60       */
61      @Override
62      public String getCreate( HttpServletRequest request )
63      {
64          HashMap<String, Object> model = new HashMap<String, Object>( );
65          String strIdPage = request.getParameter( PARAMETER_PAGE_ID );
66          String strIdPortletType = request.getParameter( PARAMETER_PORTLET_TYPE_ID );
67          model.put( CRMConstants.MARK_CATEGORIES_LIST, _categoryService.getCategories( getLocale( ), true, true ) );
68          HtmlTemplate template = getCreateTemplate( strIdPage, strIdPortletType, model );
69  
70          return template.getHtml( );
71      }
72  
73      /**
74       * {@inheritDoc}
75       */
76      @Override
77      public String getModify( HttpServletRequest request )
78      {
79  
80          HashMap<String, Object> model = new HashMap<String, Object>( );
81          String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
82          int nPortletId = CrmUtils.convertStringToInt( strPortletId );
83          DemandTypePortlet../../../fr/paris/lutece/plugins/crm/business/portlet/DemandTypePortlet.html#DemandTypePortlet">DemandTypePortlet portlet = (DemandTypePortlet) PortletHome.findByPrimaryKey( nPortletId );
84          model.put( CRMConstants.MARK_CATEGORIES_LIST, _categoryService.getCategories( getLocale( ), true, true ) );
85          model.put( CRMConstants.MARK_CATEGORY_ID_CATEGORY, portlet.getIdCategory( ) );
86  
87          HtmlTemplate template = getModifyTemplate( portlet, model );
88  
89          return template.getHtml( );
90      }
91  
92      /**
93       * {@inheritDoc}
94       */
95      @Override
96      public String doCreate( HttpServletRequest request )
97      {
98  
99          DemandTypePortletiness/portlet/DemandTypePortlet.html#DemandTypePortlet">DemandTypePortlet portlet = new DemandTypePortlet( );
100         // gets the identifier of the parent page
101         String strCategory = request.getParameter( CRMConstants.PARAMETER_CATEGORY_ID_CATEGORY );
102         int nIdCategory = CrmUtils.convertStringToInt( strCategory );
103         // get portlet common attributes
104         String strErrorUrl = setPortletCommonData( request, portlet );
105 
106         if ( strErrorUrl != null )
107         {
108             return strErrorUrl;
109         }
110 
111         portlet.setIdCategory( nIdCategory );
112 
113         // Portlet creation
114         DemandTypePortletHome.getInstance( ).create( portlet );
115 
116         // Displays the page with the new Portlet
117         return getPageUrl( portlet.getPageId( ) );
118     }
119 
120     /**
121      * {@inheritDoc}
122      */
123     @Override
124     public String doModify( HttpServletRequest request )
125     {
126         // recovers portlet attributes
127         String strPortletId = request.getParameter( PARAMETER_PORTLET_ID );
128         String strCategory = request.getParameter( CRMConstants.PARAMETER_CATEGORY_ID_CATEGORY );
129 
130         int nPortletId = CrmUtils.convertStringToInt( strPortletId );
131         int nIdCategory = CrmUtils.convertStringToInt( strCategory );
132 
133         DemandTypePortlet../../../fr/paris/lutece/plugins/crm/business/portlet/DemandTypePortlet.html#DemandTypePortlet">DemandTypePortlet portlet = (DemandTypePortlet) PortletHome.findByPrimaryKey( nPortletId );
134         // retrieve portlet common attributes
135         String strErrorUrl = setPortletCommonData( request, portlet );
136 
137         if ( strErrorUrl != null )
138         {
139             return strErrorUrl;
140         }
141 
142         portlet.setIdCategory( nIdCategory );
143 
144         // Portlet update
145         DemandTypePortletHome.getInstance( ).update( portlet );
146 
147         // displays the page withe the potlet updated
148         return getPageUrl( portlet.getPageId( ) );
149     }
150 
151 }