1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.crm.business.portlet;
35
36 import java.util.Collection;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Map;
41
42 import javax.servlet.http.HttpServletRequest;
43
44 import fr.paris.lutece.plugins.crm.business.demand.DemandType;
45 import fr.paris.lutece.plugins.crm.business.demand.category.Category;
46 import fr.paris.lutece.plugins.crm.service.category.CategoryService;
47 import fr.paris.lutece.plugins.crm.service.demand.DemandTypeService;
48 import fr.paris.lutece.plugins.crm.util.CrmUtils;
49 import fr.paris.lutece.plugins.crm.util.constants.CRMConstants;
50 import fr.paris.lutece.portal.business.portlet.Portlet;
51 import fr.paris.lutece.portal.service.i18n.I18nService;
52 import fr.paris.lutece.util.xml.XmlUtil;
53
54
55
56
57 public class DemandTypePortlet extends Portlet
58 {
59
60
61 private int _nIdCategory;
62
63
64
65
66 public DemandTypePortlet( )
67 {
68 }
69
70
71
72
73
74
75
76
77 public String getXml( HttpServletRequest request )
78 {
79
80 Locale locale;
81
82 if ( request != null )
83 {
84 locale = request.getLocale( );
85 }
86 else
87 {
88 locale = I18nService.getDefaultLocale( );
89 }
90
91 StringBuffer strXml = new StringBuffer( );
92 XmlUtil.beginElement( strXml, CRMConstants.TAG_DEMANDE_TYPE_PORTLET );
93 XmlUtil.beginElement( strXml, CRMConstants.TAG_DEMANDE_TYPE_PORTLET_CONTENT );
94 XmlUtil.beginElement( strXml, CRMConstants.TAG_CATEGORY_LIST );
95 if ( _nIdCategory != CrmUtils.CONSTANT_ID_NULL )
96 {
97 Category category = null;
98 if ( _nIdCategory != CrmUtils.convertStringToInt( CRMConstants.NO_CATEGORY ) )
99
100 {
101 category = CategoryService.getService( ).findByPrimaryKey( _nIdCategory );
102 }
103 else
104 {
105 category = new Category( );
106 category.setIdCategory( _nIdCategory );
107 category.setName( " " );
108 }
109
110 List<DemandType> listDemandType = DemandTypeService.getService( ).findForLuteceUser( request, _nIdCategory );
111 if ( category != null )
112 {
113 strXml.append( category.getXml( request, locale, listDemandType ) );
114 }
115 }
116 else
117 {
118 Collection<Category> listCategory = CategoryService.getService( ).getCategoriesList( );
119 Map<String, List<DemandType>> mapCategoryDemandType = DemandTypeService.getService( ).findForLuteceUser( request );
120 for ( Category category : listCategory )
121 {
122 strXml.append( category.getXml( request, locale, mapCategoryDemandType.get( Integer.toString( category.getIdCategory( ) ) ) ) );
123 }
124
125 }
126 XmlUtil.endElement( strXml, CRMConstants.TAG_CATEGORY_LIST );
127 XmlUtil.endElement( strXml, CRMConstants.TAG_DEMANDE_TYPE_PORTLET_CONTENT );
128 XmlUtil.endElement( strXml, CRMConstants.TAG_DEMANDE_TYPE_PORTLET );
129
130 String str = addPortletTags( strXml );
131
132 return str;
133 }
134
135
136
137
138
139
140 public int getIdCategory( )
141 {
142 return _nIdCategory;
143 }
144
145
146
147
148
149
150
151 public void setIdCategory( int _nIdCategory )
152 {
153 this._nIdCategory = _nIdCategory;
154 }
155
156
157
158
159
160
161
162
163 public String getXmlDocument( HttpServletRequest request )
164 {
165 return XmlUtil.getXmlHeader( ) + getXml( request );
166 }
167
168
169
170
171 public void update( )
172 {
173 DemandTypePortletHome.getInstance( ).update( this );
174 }
175
176
177
178
179 public void remove( )
180 {
181 DemandTypePortletHome.getInstance( ).remove( this );
182 }
183
184 @Override
185 public Map<String, String> getXslParams( )
186 {
187 Locale defaultLocale = I18nService.getDefaultLocale( );
188 HashMap<String, String> mapParams = new HashMap<String, String>( );
189 mapParams.put( CRMConstants.MARK_XSL_PARAM_I18N_LABEL_DEMAND_TYPES_LIST,
190 I18nService.getLocalizedString( CRMConstants.PROPERTY_LABEL_DEMAND_TYPES_LIST, defaultLocale ) );
191 mapParams.put( CRMConstants.MARK_XSL_PARAM_I18N_LABEL_CRM_INFO, I18nService.getLocalizedString( CRMConstants.PROPERTY_LABEL_CRM_INFO, defaultLocale ) );
192 mapParams.put( CRMConstants.MARK_XSL_PARAM_I18N_LABEL_CRM_CONTACT,
193 I18nService.getLocalizedString( CRMConstants.PROPERTY_LABEL_CRM_CONTACT, defaultLocale ) );
194 mapParams.put( CRMConstants.MARK_XSL_PARAM_I18N_LABEL_CRM_DATE_BEGIN,
195 I18nService.getLocalizedString( CRMConstants.PROPERTY_LABEL_CRM_DATE_BEGIN, defaultLocale ) );
196 mapParams.put( CRMConstants.MARK_XSL_PARAM_I18N_LABEL_CRM_DATE_END,
197 I18nService.getLocalizedString( CRMConstants.PROPERTY_LABEL_CRM_DATE_END, defaultLocale ) );
198 return mapParams;
199 }
200
201 }