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.stock.modules.billetterie.web;
35
36 import fr.paris.lutece.plugins.stock.business.category.CategoryFilter;
37 import fr.paris.lutece.plugins.stock.business.product.ProductFilter;
38 import fr.paris.lutece.plugins.stock.business.provider.ProviderFilter;
39 import fr.paris.lutece.plugins.stock.commons.ResultList;
40 import fr.paris.lutece.plugins.stock.commons.dao.PaginationProperties;
41 import fr.paris.lutece.plugins.stock.commons.exception.BusinessException;
42 import fr.paris.lutece.plugins.stock.commons.exception.FunctionnalException;
43 import fr.paris.lutece.plugins.stock.modules.billetterie.utils.constants.BilletterieConstants;
44 import fr.paris.lutece.plugins.stock.modules.tickets.business.PartnerDTO;
45 import fr.paris.lutece.plugins.stock.modules.tickets.business.SeanceDTO;
46 import fr.paris.lutece.plugins.stock.modules.tickets.business.SeanceFilter;
47 import fr.paris.lutece.plugins.stock.modules.tickets.business.ShowDTO;
48 import fr.paris.lutece.plugins.stock.modules.tickets.business.ShowFilter;
49 import fr.paris.lutece.plugins.stock.modules.tickets.service.ICategoryService;
50 import fr.paris.lutece.plugins.stock.modules.tickets.service.IProviderService;
51 import fr.paris.lutece.plugins.stock.modules.tickets.service.ISeanceService;
52 import fr.paris.lutece.plugins.stock.modules.tickets.service.IShowService;
53 import fr.paris.lutece.plugins.stock.modules.tickets.service.IStatisticService;
54 import fr.paris.lutece.plugins.stock.modules.tickets.utils.constants.TicketsConstants;
55 import fr.paris.lutece.plugins.stock.service.ISubscriptionProductService;
56 import fr.paris.lutece.plugins.stock.utils.ImageUtils;
57 import fr.paris.lutece.plugins.stock.utils.ListUtils;
58 import fr.paris.lutece.plugins.stock.utils.constants.StockConstants;
59 import fr.paris.lutece.portal.service.i18n.I18nService;
60 import fr.paris.lutece.portal.service.message.AdminMessage;
61 import fr.paris.lutece.portal.service.message.AdminMessageService;
62 import fr.paris.lutece.portal.service.resource.ExtendableResourceRemovalListenerService;
63 import fr.paris.lutece.portal.service.spring.SpringContextService;
64 import fr.paris.lutece.portal.service.template.AppTemplateService;
65 import fr.paris.lutece.portal.service.util.AppLogService;
66 import fr.paris.lutece.portal.service.util.AppPathService;
67 import fr.paris.lutece.portal.service.util.AppPropertiesService;
68 import fr.paris.lutece.portal.web.constants.Parameters;
69 import fr.paris.lutece.portal.web.resource.ExtendableResourcePluginActionManager;
70 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
71 import fr.paris.lutece.util.ReferenceList;
72 import fr.paris.lutece.util.datatable.DataTableManager;
73 import fr.paris.lutece.util.html.HtmlTemplate;
74
75 import org.apache.commons.fileupload.FileItem;
76 import org.apache.commons.io.FilenameUtils;
77 import org.apache.commons.lang.StringUtils;
78 import org.apache.log4j.Logger;
79 import org.springframework.transaction.annotation.Transactional;
80
81 import java.io.File;
82 import java.io.IOException;
83 import java.io.InputStream;
84 import java.lang.reflect.Method;
85 import java.text.SimpleDateFormat;
86 import java.util.ArrayList;
87 import java.util.Date;
88 import java.util.HashMap;
89 import java.util.List;
90 import java.util.Locale;
91 import java.util.Map;
92
93 import javax.servlet.http.HttpServletRequest;
94
95
96
97
98 public class ShowJspBean extends AbstractJspBean
99 {
100
101 public static final Logger LOGGER = Logger.getLogger( ShowJspBean.class );
102
103
104 public static final String PARAMETER_CATEGORY_ID = "product_id";
105
106
107 public static final String PARAMETER_PRODUCT_PARTNER_ID = "partnerId";
108
109
110 public static final String PARAMETER_PRODUCT_CATEGORY_ID = "categoryId";
111
112
113 public static final String RIGHT_MANAGE_PRODUCTS = "PRODUCTS_MANAGEMENT";
114
115
116 public static final String MARK_PRODUCT = "product";
117
118
119 public static final String MARK_TITLE = "title";
120
121
122 public static final String MARK_DATA_TABLE_PRODUCT = "dataTableProduct";
123 public static final String MARK_FILTER_PRODUCT = "filterProduct";
124 public static final String MACRO_COLUMN_ACTIONS_PRODUCT = "columnActionsProduct";
125 public static final String MACRO_COLUMN_NAME_PRODUCT = "columnNameProduct";
126 public static final String MACRO_COLUMN_DATES_PRODUCT = "columnDatesProduct";
127
128
129 public static final String PARAMETER_PRODUCT_TYPE_LIST = "product_type_list";
130 private static final long serialVersionUID = 5782544563181019800L;
131
132
133 public static final String PARAMETER_PRODUCT_TYPE_LIST_DEFAULT = "product_type_list_default";
134
135
136 private static final String BEAN_STOCK_TICKETS_SEANCE_SERVICE = "stock-tickets.seanceService";
137
138
139 private static final String BEAN_STOCK_TICKETS_SHOW_SERVICE = "stock-tickets.showService";
140
141
142 private static final String MARK_LIST_CATEGORIES = "category_list";
143
144
145 private static final String MARK_LIST_PROVIDERS = "provider_list";
146 private static final String MARK_CONTACT_LIST = "contact_list";
147
148 private static final String PARAMETER_PRODUCT_ID_PROVIDER = "idProvider";
149 public static final String PARAMETER_REFRESH_CONTACT = "refresh_contact";
150
151 private static final String MARK_URL_POSTER = "url_poster";
152
153
154 private static final String MARK_PUBLIC_LIST = "public_list";
155
156
157 private static final String PARAMETER_POSTER = "posterFile";
158
159
160 private static final String PARAMETER_A_LAFFICHE = "aLaffiche";
161
162
163 private static final String PROPERTY_POSTER_THUMB_WIDTH = "stock-billetterie.poster.width";
164
165
166 private static final String PROPERTY_POSTER_THUMB_HEIGHT = "stock-billetterie.poster.height";
167 private static final String PROPERTY_POSTER_MAX_HEIGHT = "stock-billetterie.poster.max-height";
168 private static final String PROPERTY_POSTER_MAX_WIDTH = "stock-billetterie.poster.max-width";
169 private static final int PROPERTY_POSTER_MAX_HEIGHT_DEFAULT = 400;
170 private static final int PROPERTY_POSTER_MAX_WIDTH_DEFAULT = 400;
171 private static final String PROPERTY_POSTER_PATH = "stock-billetterie.poster.path";
172 private static final String PROPERTY_RIMG_POSTER_PATH = "stock-billetterie.poster.rimg.path";
173
174
175 private static final String PROPERTY_STOCK_BILLETTERIE_SHOW_PUBLIC = "stock-billetterie.show.public";
176
177
178 private static final String MARK_WEBAPP_URL = "webapp_url";
179
180
181 private static final String MARK_LOCALE = "locale";
182
183
184
185 private static final String PAGE_TITLE_MANAGE_PRODUCT = "module.stock.billetterie.manage_product.title";
186
187
188 private static final String PAGE_TITLE_CREATE_PRODUCT = "module.stock.billetterie.save_product.create.title";
189
190
191 private static final String PAGE_TITLE_MODIFY_PRODUCT = "module.stock.billetterie.save_product.title";
192
193
194
195
196
197 private static final String JSP_MANAGE_PRODUCTS = "jsp/admin/plugins/stock/modules/billetterie/ManageProducts.jsp";
198
199
200 private static final String JSP_SAVE_PRODUCT = "SaveProduct.jsp";
201
202
203 private static final String CATEGORY_DO_DELETE_JSP = "jsp/admin/plugins/stock/modules/billetterie/DoDeleteProduct.jsp";
204
205
206
207 private static final String TEMPLATE_MANAGE_PRODUCTS = "admin/plugins/stock/modules/billetterie/manage_products.html";
208
209
210 private static final String TEMPLATE_SAVE_PRODUCT = "admin/plugins/stock/modules/billetterie/save_product.html";
211
212
213
214
215
216
217 private static final String MESSAGE_CONFIRMATION_DELETE_PRODUCT = "module.stock.billetterie.message.deleteProduct.confirmation";
218
219
220 private static final String MESSAGE_DELETE_SHOW_WITH_SEANCE = "module.stock.billetterie.message.deleteProduct.with.seance";
221
222
223 private static final String MESSAGE_ERROR_MANDATORY_POSTER = "module.stock.billetterie.message.error.mandatory_poster";
224
225
226 private static final String MESSAGE_ERROR_GET_AFFICHE = "module.stock.billetterie.message.error.get.affiche";
227
228
229
230
231
232 private IShowService _serviceProduct;
233
234
235
236
237 private ISeanceService _serviceOffer;
238
239
240
241 private IProviderService _serviceProvider;
242
243
244
245 private ICategoryService _serviceCategory;
246
247
248
249 private IStatisticService _serviceStatistic;
250 private ISubscriptionProductService _subscriptionProductService;
251
252
253 private transient ProductFilter _productFilter;
254
255
256
257
258 public ShowJspBean( )
259 {
260 _productFilter = new ShowFilter( );
261 _serviceProduct = (IShowService) SpringContextService.getBean( BEAN_STOCK_TICKETS_SHOW_SERVICE );
262 _serviceOffer = (ISeanceService) SpringContextService.getBean( BEAN_STOCK_TICKETS_SEANCE_SERVICE );
263 _serviceProvider = SpringContextService.getContext( ).getBean( IProviderService.class );
264 _serviceCategory = SpringContextService.getContext( ).getBean( ICategoryService.class );
265 _serviceStatistic = SpringContextService.getContext( ).getBean( IStatisticService.class );
266 _subscriptionProductService = SpringContextService.getContext( ).getBean( ISubscriptionProductService.class );
267 }
268
269
270
271
272
273
274
275
276 public String getManageProducts( HttpServletRequest request )
277 {
278
279
280 setPageTitleProperty( PAGE_TITLE_MANAGE_PRODUCT );
281
282 ProductFilter filter = getProductFilter( request );
283 List<String> orderList = new ArrayList<String>( );
284 orderList.add( BilletterieConstants.NAME );
285 filter.setOrderAsc( true );
286 if ( filter.getOrders( ) != null && filter.getOrders( ).size( ) > 0 )
287 {
288 filter.setOrders( filter.getOrders( ) );
289 }
290 else
291 {
292 filter.setOrders( orderList );
293 }
294
295
296
297
298
299 DataTableManager<ShowDTO> dataTableToUse = getDataTable( request, filter );
300
301 Map<String, Object> model = new HashMap<String, Object>( );
302
303 model.put( MARK_DATA_TABLE_PRODUCT, dataTableToUse );
304
305
306 model.put( TicketsConstants.MARK_NB_ITEMS_PER_PAGE, String.valueOf( _nItemsPerPage ) );
307
308
309 ProviderFilter providerFilter = new ProviderFilter( );
310 providerFilter.setOrderAsc( true );
311 providerFilter.setOrders( orderList );
312
313 ReferenceList providerComboList = ListUtils.toReferenceList( _serviceProvider.findByFilter( providerFilter, null ), BilletterieConstants.ID,
314 BilletterieConstants.NAME, StockConstants.EMPTY_STRING );
315 CategoryFilter categoryFilter = new CategoryFilter( );
316 categoryFilter.setOrderAsc( true );
317 categoryFilter.setOrders( orderList );
318
319 ReferenceList categoryComboList = ListUtils.toReferenceList( _serviceCategory.findByFilter( categoryFilter, null ), BilletterieConstants.ID,
320 BilletterieConstants.NAME, StockConstants.EMPTY_STRING );
321 model.put( MARK_LIST_PROVIDERS, providerComboList );
322 model.put( MARK_LIST_CATEGORIES, categoryComboList );
323
324 model.put( TicketsConstants.MARK_FILTER, filter );
325 model.put( MARK_LOCALE, getLocale( ) );
326 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_PRODUCTS, getLocale( ), model );
327
328
329 dataTableToUse.clearItems( );
330
331 return getAdminPage( template.getHtml( ) );
332 }
333
334
335
336
337
338
339
340
341
342
343 private DataTableManager<ShowDTO> getDataTable( HttpServletRequest request, ProductFilter filter )
344 {
345
346 Method findMethod = null;
347
348 try
349 {
350 findMethod = _serviceProduct.getClass( ).getMethod( PARAMETER_FIND_BY_FILTER_NAME_METHOD, ProductFilter.class, PaginationProperties.class );
351 }
352 catch( Exception e )
353 {
354 LOGGER.error( "Erreur lors de l'obtention du data table : ", e );
355 }
356
357 DataTableManager<ShowDTO> dataTableToUse = getAbstractDataTableManager( request, filter, MARK_DATA_TABLE_PRODUCT, JSP_MANAGE_PRODUCTS, _serviceProduct,
358 findMethod );
359
360
361 if ( dataTableToUse.getListColumn( ).isEmpty( ) )
362 {
363 dataTableToUse.addColumn( "module.stock.billetterie.manage_product.filter.name", "name", true );
364 dataTableToUse.addColumn( "module.stock.billetterie.manage_product.filter.provider", "providerName", true );
365 dataTableToUse.addColumn( "module.stock.billetterie.manage_product.filter.category", "categoryName", true );
366
367
368 dataTableToUse.addFreeColumn( "module.stock.billetterie.manage_product.dates", MACRO_COLUMN_DATES_PRODUCT );
369 dataTableToUse.addFreeColumn( "module.stock.billetterie.manage_product.actionsLabel", MACRO_COLUMN_ACTIONS_PRODUCT );
370 }
371
372 saveDataTableInSession( request, dataTableToUse, MARK_DATA_TABLE_PRODUCT );
373
374 return dataTableToUse;
375 }
376
377 private ReferenceList getContactComboList( int idProvider )
378 {
379 PartnerDTO findById = _serviceProvider.findById( idProvider );
380 ReferenceList contactComboList = ListUtils.toReferenceList( findById.getContactList( ), BilletterieConstants.ID, BilletterieConstants.NAME,
381 StockConstants.EMPTY_STRING );
382 return contactComboList;
383 }
384
385
386
387
388
389
390
391
392
393
394 @Transactional( readOnly = true )
395 public String getSaveProduct( HttpServletRequest request, String strProductClassName )
396 {
397 ShowDTO product = null;
398 Map<String, Object> model = new HashMap<String, Object>( );
399
400 FunctionnalException fe = getErrorOnce( request );
401
402 if ( fe != null )
403 {
404 product = (ShowDTO) fe.getBean( );
405 model.put( BilletterieConstants.ERROR, getHtmlError( fe ) );
406 }
407 else
408 {
409 String strProductId = request.getParameter( PARAMETER_CATEGORY_ID );
410 String strPartnerId = request.getParameter( PARAMETER_PRODUCT_PARTNER_ID );
411 String strCategoryId = request.getParameter( PARAMETER_PRODUCT_CATEGORY_ID );
412
413 if ( strProductId != null )
414 {
415 setPageTitleProperty( PAGE_TITLE_MODIFY_PRODUCT );
416
417 int nIdProduct = Integer.parseInt( strProductId );
418 product = _serviceProduct.findById( nIdProduct );
419
420 int idProvider = product.getIdProvider( );
421
422 if ( request.getParameter( PARAMETER_REFRESH_CONTACT ) != null )
423 {
424
425
426 populate( product, request );
427 String strIdProvider = request.getParameter( PARAMETER_PRODUCT_ID_PROVIDER );
428 int nIdSelectedProvider = Integer.valueOf( strIdProvider );
429
430 if ( nIdSelectedProvider >= 0 )
431 {
432 idProvider = nIdSelectedProvider;
433 }
434
435 }
436
437 model.put( MARK_CONTACT_LIST, getContactComboList( idProvider ) );
438
439 _serviceProduct.correctProduct( product );
440 }
441 else
442 {
443 setPageTitleProperty( PAGE_TITLE_CREATE_PRODUCT );
444 product = new ShowDTO( );
445
446
447 if ( StringUtils.isNotBlank( strPartnerId ) )
448 {
449 product.setIdProvider( Integer.parseInt( strPartnerId ) );
450 }
451 else
452 {
453 populate( product, request );
454 }
455
456
457
458 if ( StringUtils.isNotBlank( strCategoryId ) )
459 {
460 product.setIdCategory( Integer.parseInt( strCategoryId ) );
461 }
462
463 if ( ( request.getParameter( PARAMETER_PRODUCT_ID_PROVIDER ) != null ) && !request.getParameter( PARAMETER_PRODUCT_ID_PROVIDER ).equals( "-1" ) )
464 {
465 Integer idProvider = Integer.valueOf( request.getParameter( PARAMETER_PRODUCT_ID_PROVIDER ) );
466
467 model.put( MARK_CONTACT_LIST, getContactComboList( idProvider ) );
468 }
469 }
470 }
471
472 if ( request instanceof MultipartHttpServletRequest )
473 {
474 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
475 FileItem fileItem = multipartRequest.getFile( PARAMETER_POSTER );
476
477 if ( ( fileItem != null ) && ( fileItem.getSize( ) > 0 ) )
478 {
479
480 product.setPosterName( fileItem.getName( ) );
481 populate( product, request );
482 }
483 }
484
485
486 List<String> orderList = new ArrayList<String>( );
487 orderList.add( BilletterieConstants.NAME );
488
489 ProviderFilter providerFilter = new ProviderFilter( );
490 providerFilter.setOrderAsc( true );
491 providerFilter.setOrders( orderList );
492
493 ReferenceList providerComboList = ListUtils.toReferenceList( _serviceProvider.findByFilter( providerFilter, null ), BilletterieConstants.ID,
494 BilletterieConstants.NAME, StockConstants.EMPTY_STRING );
495 CategoryFilter categoryFilter = new CategoryFilter( );
496 categoryFilter.setOrderAsc( true );
497 categoryFilter.setOrders( orderList );
498
499 ReferenceList categoryComboList = ListUtils.toReferenceList( _serviceCategory.findByFilter( categoryFilter, null ), BilletterieConstants.ID,
500 BilletterieConstants.NAME, StockConstants.EMPTY_STRING );
501 model.put( MARK_LIST_PROVIDERS, providerComboList );
502 model.put( MARK_LIST_CATEGORIES, categoryComboList );
503 model.put( MARK_PUBLIC_LIST, ListUtils.getPropertyList( PROPERTY_STOCK_BILLETTERIE_SHOW_PUBLIC ) );
504
505 model.put( StockConstants.MARK_JSP_BACK, request.getParameter( StockConstants.MARK_JSP_BACK ) );
506 model.put( MARK_PRODUCT, product );
507 model.put( MARK_URL_POSTER, AppPropertiesService.getProperty( PROPERTY_RIMG_POSTER_PATH ) );
508
509
510 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
511 model.put( MARK_LOCALE, getLocale( ) );
512
513 if ( ( product.getId( ) != null ) && ( product.getId( ) != 0 ) )
514 {
515 model.put( MARK_TITLE, I18nService.getLocalizedString( PAGE_TITLE_MODIFY_PRODUCT, Locale.getDefault( ) ) );
516 }
517 else
518 {
519 model.put( MARK_TITLE, I18nService.getLocalizedString( PAGE_TITLE_CREATE_PRODUCT, Locale.getDefault( ) ) );
520 }
521
522 ExtendableResourcePluginActionManager.fillModel( request, getUser( ), model, String.valueOf( product.getId( ) ), ShowDTO.PROPERTY_RESOURCE_TYPE );
523
524 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_SAVE_PRODUCT, getLocale( ), model );
525
526 return getAdminPage( template.getHtml( ) );
527 }
528
529
530
531
532
533
534
535
536 public String doSaveProduct( HttpServletRequest request )
537 {
538 if ( null != request.getParameter( StockConstants.PARAMETER_BUTTON_CANCEL ) )
539 {
540 return doGoBack( request );
541 }
542
543 String strUpdateDate = getToday( );
544
545 ShowDTO product = new ShowDTO( );
546 populate( product, request );
547
548 product.setUpdateDate( strUpdateDate );
549
550 if ( StringUtils.isNotEmpty( request.getParameter( PARAMETER_A_LAFFICHE ) ) )
551 {
552 product.setAlaffiche( true );
553 }
554
555 try
556 {
557
558 File [ ] filePosterArray = writePoster( request, product );
559
560
561 validateBilletterie( product );
562
563
564 ShowDTO saveProduct = _serviceProduct.doSaveProduct( product, filePosterArray );
565
566
567 _serviceStatistic.doManageProductSaving( saveProduct );
568 }
569 catch( FunctionnalException e )
570 {
571 return manageFunctionnalException( request, e, JSP_SAVE_PRODUCT );
572 }
573
574 return doGoBack( request );
575 }
576
577
578
579
580
581
582
583
584
585
586
587
588 private File [ ] writePoster( HttpServletRequest request, ShowDTO product ) throws BusinessException
589 {
590 File [ ] filePosterArray = null;
591 boolean fileGotten = false;
592
593
594 if ( request instanceof MultipartHttpServletRequest )
595 {
596 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
597 FileItem fileItem = multipartRequest.getFile( PARAMETER_POSTER );
598
599 if ( ( fileItem != null ) && ( fileItem.getSize( ) > 0 ) )
600 {
601 InputStream fisPoster = null;
602 InputStream realFisPoster = null;
603
604 try
605 {
606 fisPoster = fileItem.getInputStream( );
607 realFisPoster = fileItem.getInputStream( );
608
609
610
611 File fPoster = File.createTempFile( FilenameUtils.getBaseName( fileItem.getName( ) ), null );
612 File realPoster = File.createTempFile( FilenameUtils.getBaseName( fileItem.getName( ) ), null );
613
614
615 fPoster = fr.paris.lutece.plugins.stock.utils.FileUtils.getUniqueFile( fPoster );
616 realPoster = fr.paris.lutece.plugins.stock.utils.FileUtils.getUniqueFile( realPoster );
617
618
619 fr.paris.lutece.plugins.stock.utils.FileUtils.writeInputStreamToFile( fisPoster, fPoster );
620 fr.paris.lutece.plugins.stock.utils.FileUtils.writeInputStreamToFile( realFisPoster, realPoster );
621
622 File fPosterResize = ImageUtils.resizeImage( fPoster,
623 AppPropertiesService.getPropertyInt( PROPERTY_POSTER_MAX_WIDTH, PROPERTY_POSTER_MAX_WIDTH_DEFAULT ),
624 AppPropertiesService.getPropertyInt( PROPERTY_POSTER_MAX_HEIGHT, PROPERTY_POSTER_MAX_HEIGHT_DEFAULT ), null );
625
626
627 File fTbPoster = ImageUtils.createThumbnail( fPoster, AppPropertiesService.getPropertyInt( PROPERTY_POSTER_THUMB_WIDTH, 120 ),
628 AppPropertiesService.getPropertyInt( PROPERTY_POSTER_THUMB_HEIGHT, 200 ) );
629
630
631 product.setPosterName( fPoster.getName( ) );
632 fileGotten = true;
633
634 filePosterArray = new File [ ] {
635 fTbPoster, fPosterResize, realPoster
636 };
637 }
638 catch( IOException e )
639 {
640 throw new BusinessException( product, MESSAGE_ERROR_GET_AFFICHE );
641 }
642 finally
643 {
644 if ( fisPoster != null )
645 {
646 try
647 {
648 fisPoster.close( );
649 }
650 catch( IOException e )
651 {
652 AppLogService.error( e.getMessage( ), e );
653 }
654 }
655 }
656 }
657 }
658
659 if ( !fileGotten )
660 {
661
662 if ( StringUtils.isEmpty( product.getPosterName( ) ) )
663 {
664 throw new BusinessException( product, MESSAGE_ERROR_MANDATORY_POSTER );
665 }
666 }
667
668 return filePosterArray;
669 }
670
671
672
673
674
675
676
677
678 private String doGoBack( HttpServletRequest request )
679 {
680 String strJspBack = request.getParameter( StockConstants.MARK_JSP_BACK );
681
682 return StringUtils.isNotBlank( strJspBack ) ? ( AppPathService.getBaseUrl( request ) + strJspBack )
683 : ( AppPathService.getBaseUrl( request ) + JSP_MANAGE_PRODUCTS );
684 }
685
686
687
688
689
690
691
692
693 private ProductFilter getProductFilter( HttpServletRequest request )
694 {
695
696 String strSortedAttributeName = request.getParameter( Parameters.SORTED_ATTRIBUTE_NAME );
697
698
699
700
701
702 ProductFilter filter = new ShowFilter( );
703 populate( filter, request );
704
705 if ( StringUtils.isNotEmpty( request.getParameter( PARAMETER_A_LAFFICHE ) ) )
706 {
707 filter.setAlaffiche( true );
708 }
709
710 _productFilter = filter;
711
712
713 if ( strSortedAttributeName != null )
714 {
715 _productFilter.getOrders( ).add( strSortedAttributeName );
716
717 String strAscSort = request.getParameter( Parameters.SORTED_ASC );
718 boolean bIsAscSort = Boolean.parseBoolean( strAscSort );
719 _productFilter.setOrderAsc( bIsAscSort );
720 }
721
722 return _productFilter;
723 }
724
725
726
727
728
729
730
731
732 public String getDeleteProduct( HttpServletRequest request )
733 {
734 String strProductId = request.getParameter( PARAMETER_CATEGORY_ID );
735
736 int nIdProduct;
737
738 try
739 {
740 nIdProduct = Integer.parseInt( strProductId );
741 }
742 catch( NumberFormatException e )
743 {
744 LOGGER.debug( e );
745
746 return AdminMessageService.getMessageUrl( request, StockConstants.MESSAGE_ERROR_OCCUR, AdminMessage.TYPE_STOP );
747 }
748
749 Map<String, Object> urlParam = new HashMap<String, Object>( );
750 urlParam.put( PARAMETER_CATEGORY_ID, nIdProduct );
751
752 String strJspBack = request.getParameter( StockConstants.MARK_JSP_BACK );
753
754 if ( StringUtils.isNotBlank( strJspBack ) )
755 {
756 urlParam.put( StockConstants.MARK_JSP_BACK, strJspBack );
757 }
758
759
760 SeanceFilter filter = new SeanceFilter( );
761 filter.setProductId( nIdProduct );
762
763 ResultList<SeanceDTO> bookingList = _serviceOffer.findByFilter( filter, null );
764
765 if ( ( bookingList != null ) && !bookingList.isEmpty( ) )
766 {
767 return AdminMessageService.getMessageUrl( request, MESSAGE_DELETE_SHOW_WITH_SEANCE, AdminMessage.TYPE_STOP );
768 }
769
770 return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRMATION_DELETE_PRODUCT, CATEGORY_DO_DELETE_JSP, AdminMessage.TYPE_CONFIRMATION,
771 urlParam );
772 }
773
774
775
776
777
778
779
780
781 public String doDeleteProduct( HttpServletRequest request )
782 {
783 String strProductId = request.getParameter( PARAMETER_CATEGORY_ID );
784
785 int nIdProduct;
786
787 try
788 {
789 nIdProduct = Integer.parseInt( strProductId );
790 }
791 catch( NumberFormatException e )
792 {
793 LOGGER.debug( e );
794
795 return AdminMessageService.getMessageUrl( request, StockConstants.MESSAGE_ERROR_OCCUR, AdminMessage.TYPE_STOP );
796 }
797
798
799 _serviceStatistic.doRemoveProductStatisticByIdProduct( nIdProduct );
800
801
802 _subscriptionProductService.doDeleteByIdProduct( strProductId );
803
804 _serviceProduct.doDeleteProduct( nIdProduct );
805
806
807 ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( ShowDTO.PROPERTY_RESOURCE_TYPE, Integer.toString( nIdProduct ) );
808
809 return doGoBack( request );
810 }
811
812
813
814
815
816
817 public String getToday( )
818 {
819 String format = "dd/MM/yyyy";
820 SimpleDateFormat formater = new java.text.SimpleDateFormat( format );
821 Date date = new java.util.Date( );
822 return formater.format( date );
823 }
824 }