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.myapps.modules.database.web;
35
36 import fr.paris.lutece.plugins.myapps.business.MyApps;
37 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabase;
38 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabaseCategory;
39 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabaseCategoryHome;
40 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabaseFilter;
41 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabaseHome;
42 import fr.paris.lutece.plugins.myapps.modules.database.service.MyAppsDatabaseResourceIdService;
43 import fr.paris.lutece.plugins.myapps.modules.database.service.MyAppsDatabaseService;
44 import fr.paris.lutece.plugins.myapps.modules.database.utils.constants.MyAppsDatabaseConstants;
45 import fr.paris.lutece.portal.business.rbac.RBAC;
46 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
47 import fr.paris.lutece.portal.service.i18n.I18nService;
48 import fr.paris.lutece.portal.service.message.AdminMessage;
49 import fr.paris.lutece.portal.service.message.AdminMessageService;
50 import fr.paris.lutece.portal.service.rbac.RBACService;
51 import fr.paris.lutece.portal.service.template.AppTemplateService;
52 import fr.paris.lutece.portal.service.util.AppLogService;
53 import fr.paris.lutece.portal.service.util.AppPathService;
54 import fr.paris.lutece.portal.service.util.AppPropertiesService;
55 import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
56 import fr.paris.lutece.portal.web.constants.Messages;
57 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
58 import fr.paris.lutece.portal.web.util.LocalizedPaginator;
59 import fr.paris.lutece.util.html.HtmlTemplate;
60 import fr.paris.lutece.util.html.Paginator;
61 import fr.paris.lutece.util.url.UrlItem;
62
63 import org.apache.commons.fileupload.FileItem;
64 import org.apache.commons.lang.StringUtils;
65
66 import java.util.HashMap;
67 import java.util.List;
68 import java.util.Map;
69
70 import javax.servlet.http.HttpServletRequest;
71
72
73
74
75
76
77 public class MyAppsDatabaseJspBean extends PluginAdminPageJspBean
78 {
79 public static final String RIGHT_MYAPPS_DATABASE_MANAGEMENT = "MYAPPS_DATABASE_MANAGEMENT";
80
81
82 private int _nItemsPerPage;
83 private int _nDefaultItemsPerPage = AppPropertiesService.getPropertyInt( MyAppsDatabaseConstants.PROPERTY_DEFAULT_ITEMS_PER_PAGE, 50 );
84 private String _strCurrentPageIndex;
85 private String _strCategoryFilter;
86
87
88
89
90 public MyAppsDatabaseJspBean( )
91 {
92 }
93
94
95
96
97
98
99
100
101 public String getManageMyApps( HttpServletRequest request )
102 {
103 setPageTitleProperty( MyAppsDatabaseConstants.PROPERTY_PAGE_TITLE_MYAPPS );
104 _strCurrentPageIndex = Paginator.getPageIndex( request, Paginator.PARAMETER_PAGE_INDEX, _strCurrentPageIndex );
105 _nItemsPerPage = Paginator.getItemsPerPage( request, Paginator.PARAMETER_ITEMS_PER_PAGE, _nItemsPerPage, _nDefaultItemsPerPage );
106
107 _strCategoryFilter = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY ) != null ? request
108 .getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY ) : _strCategoryFilter;
109 MyAppsDatabaseFilter filter = new MyAppsDatabaseFilter( );
110 filter.setCategory( _strCategoryFilter );
111 List<MyApps> listMyApps = MyAppsDatabaseService.getInstance( ).selectMyAppsList( filter, getPlugin( ) );
112 LocalizedPaginator paginator = new LocalizedPaginator( listMyApps, _nItemsPerPage, getHomeUrl( request ), MyAppsDatabaseConstants.PARAMETER_PAGE_INDEX,
113 _strCurrentPageIndex, getLocale( ) );
114 Map<String, Object> model = new HashMap<String, Object>( );
115 model.put( MyAppsDatabaseConstants.MARK_PAGINATOR, paginator );
116 model.put( MyAppsDatabaseConstants.MARK_NB_ITEMS_PER_PAGE, String.valueOf( _nItemsPerPage ) );
117 model.put( MyAppsDatabaseConstants.MARK_MYAPPS_LIST, paginator.getPageItems( ) );
118 model.put( MyAppsDatabaseConstants.MARK_MYAPPS_CATEGORY_LIST, MyAppsDatabaseCategoryHome.getMyAppsCategoryRefList( getPlugin( ) ) );
119 model.put( MyAppsDatabaseConstants.MARK_PERMISSION_CREATE_MYAPP, RBACService.isAuthorized( MyAppsDatabase.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
120 MyAppsDatabaseResourceIdService.PERMISSION_CREATE_MYAPPS_DATABASE, getUser( ) ) );
121 model.put( MyAppsDatabaseConstants.MARK_PERMISSIONS_LIST, MyAppsDatabaseService.getInstance( ).getMyAppsPermissions( listMyApps, getUser( ) ) );
122 model.put( MyAppsDatabaseConstants.MARK_PERMISSION_MODIFY_MYAPP, MyAppsDatabaseResourceIdService.PERMISSION_MODIFY_MYAPPS_DATABASE );
123 model.put( MyAppsDatabaseConstants.MARK_PERMISSION_DELETE_MYAPP, MyAppsDatabaseResourceIdService.PERMISSION_DELETE_MYAPPS_DATABASE );
124 model.put( MyAppsDatabaseConstants.MARK_MYAPP_CODE_CATEGORY_FILTER, _strCategoryFilter );
125 HtmlTemplate templateList = AppTemplateService.getTemplate( MyAppsDatabaseConstants.TEMPLATE_MYAPPS, getLocale( ), model );
126
127 return getAdminPage( templateList.getHtml( ) );
128 }
129
130
131
132
133
134
135
136
137 public String getManageMyAppsCategory( HttpServletRequest request )
138 {
139 setPageTitleProperty( MyAppsDatabaseConstants.PROPERTY_PAGE_TITLE_MYAPPS_CATEGORY );
140 Map<String, Object> model = new HashMap<String, Object>( );
141 model.put( MyAppsDatabaseConstants.MARK_MYAPPS_CATEGORY_LIST, MyAppsDatabaseCategoryHome.getMyAppsCategoryList( getPlugin( ) ) );
142 HtmlTemplate templateList = AppTemplateService.getTemplate( MyAppsDatabaseConstants.TEMPLATE_MYAPPS_CATEGORY, getLocale( ), model );
143
144 return getAdminPage( templateList.getHtml( ) );
145 }
146
147
148
149
150
151
152
153
154 public String getConfirmRemoveMyApp( HttpServletRequest request )
155 {
156 String strUrl = StringUtils.EMPTY;
157 String strMyAppId = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID );
158
159 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
160 {
161 UrlItem url = new UrlItem( MyAppsDatabaseConstants.JSP_DO_REMOVE_MYAPP );
162 url.addParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID, request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID ) );
163
164 strUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_CONFIRM_REMOVE_MYAPP, url.getUrl( ),
165 AdminMessage.TYPE_CONFIRMATION );
166 }
167 else
168 {
169 strUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP );
170 }
171
172 return strUrl;
173 }
174
175 public String getConfirmRemoveMyAppCategory( HttpServletRequest request )
176 {
177 String strUrl = StringUtils.EMPTY;
178 String strMyAppCode = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
179
180 if ( StringUtils.isNotBlank( strMyAppCode ) )
181 {
182
183 MyAppsDatabaseFilter filter = new MyAppsDatabaseFilter( );
184 filter.setCategory( strMyAppCode );
185 List<MyApps> listMyApps = MyAppsDatabaseHome.selectMyAppsList( filter, getPlugin( ) );
186 if ( listMyApps != null && listMyApps.size( ) > 0 )
187 {
188
189 strUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR_CAN_NOT_REMOVE_MYAPP_CATEGORY,
190 AdminMessage.TYPE_STOP );
191 }
192 else
193 {
194
195 UrlItem url = new UrlItem( MyAppsDatabaseConstants.JSP_DO_REMOVE_MYAPP_CATEGORY );
196 url.addParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY,
197 request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY ) );
198 strUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_CONFIRM_REMOVE_MYAPP_CATEGORY, url.getUrl( ),
199 AdminMessage.TYPE_CONFIRMATION );
200 }
201 }
202 else
203 {
204 strUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP );
205 }
206
207 return strUrl;
208 }
209
210
211
212
213
214
215
216
217
218
219 public String doRemoveMyApp( HttpServletRequest request ) throws AccessDeniedException
220 {
221 String strJspUrl = StringUtils.EMPTY;
222 String strMyAppId = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID );
223
224 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
225 {
226 if ( !RBACService.isAuthorized( MyApps.RESOURCE_TYPE, strMyAppId, MyAppsDatabaseResourceIdService.PERMISSION_DELETE_MYAPPS_DATABASE, getUser( ) ) )
227 {
228 throw new AccessDeniedException( );
229 }
230
231 int nAppId = Integer.parseInt( strMyAppId );
232 MyAppsDatabaseService.getInstance( ).remove( nAppId, getPlugin( ) );
233
234 return getHomeUrl( request );
235 }
236 else
237 {
238 strJspUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP );
239 }
240
241 return strJspUrl;
242 }
243
244 public String doRemoveMyAppCategory( HttpServletRequest request ) throws AccessDeniedException
245 {
246 String strJspUrl = StringUtils.EMPTY;
247 String strMyAppCode = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
248
249 if ( StringUtils.isNotBlank( strMyAppCode ) )
250 {
251
252 MyAppsDatabaseCategoryHome.remove( strMyAppCode, getPlugin( ) );
253 return AppPathService.getBaseUrl( request ) + MyAppsDatabaseConstants.JSP_MANAGE_MYAPP_CATEGORY;
254 }
255 else
256 {
257 strJspUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP );
258 }
259
260 return strJspUrl;
261 }
262
263
264
265
266
267
268
269
270
271
272 public String getModifyMyApp( HttpServletRequest request ) throws AccessDeniedException
273 {
274 setPageTitleProperty( MyAppsDatabaseConstants.PROPERTY_PAGE_TITLE_MODIFY );
275
276 String strHtml = StringUtils.EMPTY;
277 String strMyAppId = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID );
278
279 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
280 {
281 if ( !RBACService.isAuthorized( MyApps.RESOURCE_TYPE, strMyAppId, MyAppsDatabaseResourceIdService.PERMISSION_MODIFY_MYAPPS_DATABASE, getUser( ) ) )
282 {
283 throw new AccessDeniedException( );
284 }
285
286 int nMyAppId = Integer.parseInt( strMyAppId );
287 MyAppsDatabase myApp = (MyAppsDatabase) MyAppsDatabaseService.getInstance( ).findByPrimaryKey( nMyAppId, getPlugin( ) );
288
289 Map<String, Object> model = new HashMap<String, Object>( );
290 model.put( MyAppsDatabaseConstants.MARK_MYAPP, myApp );
291 model.put( MyAppsDatabaseConstants.MARK_MYAPPS_CATEGORY_LIST, MyAppsDatabaseCategoryHome.getMyAppsCategoryRefList( getPlugin( ) ) );
292 HtmlTemplate template = AppTemplateService.getTemplate( MyAppsDatabaseConstants.TEMPLATE_MODIFY_APPLICATION, getLocale( ), model );
293
294 strHtml = getAdminPage( template.getHtml( ) );
295 }
296 else
297 {
298 getManageMyApps( request );
299 }
300
301 return strHtml;
302 }
303
304 public String getModifyMyAppCategory( HttpServletRequest request ) throws AccessDeniedException
305 {
306 setPageTitleProperty( MyAppsDatabaseConstants.PROPERTY_PAGE_TITLE_MODIFY_CATEGORY );
307
308 String strHtml = StringUtils.EMPTY;
309 String strMyAppCode = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
310
311 if ( StringUtils.isNotBlank( strMyAppCode ) )
312 {
313
314 MyAppsDatabaseCategory myAppCategory = (MyAppsDatabaseCategory) MyAppsDatabaseCategoryHome.findByPrimaryKey( strMyAppCode, getPlugin( ) );
315
316 Map<String, Object> model = new HashMap<String, Object>( );
317 model.put( MyAppsDatabaseConstants.MARK_MYAPP_CATEGORY, myAppCategory );
318
319 HtmlTemplate template = AppTemplateService.getTemplate( MyAppsDatabaseConstants.TEMPLATE_MODIFY_CATEGORY, getLocale( ), model );
320
321 strHtml = getAdminPage( template.getHtml( ) );
322 }
323 else
324 {
325 getManageMyAppsCategory( request );
326 }
327
328 return strHtml;
329 }
330
331 public String doModifyMyAppCategory( HttpServletRequest request ) throws AccessDeniedException
332 {
333 String strJspUrl = StringUtils.EMPTY;
334 String strMyAppCodeCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
335
336 if ( StringUtils.isNotBlank( strMyAppCodeCategory ) )
337 {
338
339 String strLibelleCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_LIBELLE_CATEGORY );
340
341 if ( StringUtils.isBlank( strLibelleCategory ) )
342 {
343
344 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
345
346 }
347
348 MyAppsDatabaseCategory category = new MyAppsDatabaseCategory( );
349 category.setCodeCategory( strMyAppCodeCategory );
350 category.setLibelleCategory( strLibelleCategory );
351
352 MyAppsDatabaseCategoryHome.update( category, getPlugin( ) );
353
354 return AppPathService.getBaseUrl( request ) + MyAppsDatabaseConstants.JSP_MANAGE_MYAPP_CATEGORY;
355
356 }
357 else
358 {
359 strJspUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP );
360 }
361
362 return strJspUrl;
363 }
364
365
366
367
368
369
370
371
372
373
374 public String getCreateMyApp( HttpServletRequest request ) throws AccessDeniedException
375 {
376 setPageTitleProperty( MyAppsDatabaseConstants.PROPERTY_PAGE_TITLE_CREATE );
377
378 if ( !RBACService.isAuthorized( MyApps.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, MyAppsDatabaseResourceIdService.PERMISSION_CREATE_MYAPPS_DATABASE,
379 getUser( ) ) )
380 {
381 throw new AccessDeniedException( );
382 }
383 Map<String, Object> model = new HashMap<String, Object>( );
384 model.put( MyAppsDatabaseConstants.MARK_MYAPPS_CATEGORY_LIST, MyAppsDatabaseCategoryHome.getMyAppsCategoryRefList( getPlugin( ) ) );
385 HtmlTemplate template = AppTemplateService.getTemplate( MyAppsDatabaseConstants.TEMPLATE_CREATE_APPLICATION, getLocale( ), model );
386
387 return getAdminPage( template.getHtml( ) );
388 }
389
390 public String getCreateMyAppCategory( HttpServletRequest request ) throws AccessDeniedException
391 {
392 setPageTitleProperty( MyAppsDatabaseConstants.PROPERTY_PAGE_TITLE_CREATE_CATEGORY );
393
394 HtmlTemplate template = AppTemplateService.getTemplate( MyAppsDatabaseConstants.TEMPLATE_CREATE_CATEGORY, getLocale( ), null );
395
396 return getAdminPage( template.getHtml( ) );
397 }
398
399 public String doCreateMyAppCategory( HttpServletRequest request ) throws AccessDeniedException
400 {
401
402 String strMyAppCodeCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
403 String strLibelleCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_LIBELLE_CATEGORY );
404
405 if ( StringUtils.isBlank( strMyAppCodeCategory ) && StringUtils.isBlank( strLibelleCategory ) )
406 {
407
408 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
409
410 }
411
412 if ( MyAppsDatabaseCategoryHome.findByPrimaryKey( strMyAppCodeCategory, getPlugin( ) ) != null )
413 {
414
415 return AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_FIELD_CATEGORY_ALREADY_EXIST, AdminMessage.TYPE_STOP );
416 }
417
418 MyAppsDatabaseCategory category = new MyAppsDatabaseCategory( );
419 category.setCodeCategory( strMyAppCodeCategory );
420 category.setLibelleCategory( strLibelleCategory );
421
422 MyAppsDatabaseCategoryHome.create( category, getPlugin( ) );
423
424 return AppPathService.getBaseUrl( request ) + MyAppsDatabaseConstants.JSP_MANAGE_MYAPP_CATEGORY;
425
426 }
427
428
429
430
431
432
433
434
435
436
437 public String doCreateMyApp( HttpServletRequest request ) throws AccessDeniedException
438 {
439 if ( !RBACService.isAuthorized( MyAppsDatabase.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
440 MyAppsDatabaseResourceIdService.PERMISSION_CREATE_MYAPPS_DATABASE, getUser( ) ) )
441 {
442 throw new AccessDeniedException( );
443 }
444
445 String strJspUrl = StringUtils.EMPTY;
446 String strAppName = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_NAME );
447 String strUrl = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_URL );
448 String strPassword = request.getParameter( MyAppsDatabaseConstants.PARAMETER_PASSWORD );
449 String strCode = request.getParameter( MyAppsDatabaseConstants.PARAMETER_CODE );
450 String strCodeHeading = request.getParameter( MyAppsDatabaseConstants.PARAMETER_CODE_HEADING );
451 String strData = request.getParameter( MyAppsDatabaseConstants.PARAMETER_DATA );
452 String strDataHeading = request.getParameter( MyAppsDatabaseConstants.PARAMETER_DATA_HEADING );
453 String strDescription = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_DESCRIPTION );
454 String strCodeCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
455
456 String strError = verifyFields( request );
457
458 if ( StringUtils.isBlank( strError ) )
459 {
460
461 MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
462 MyAppsDatabase myApp = new MyAppsDatabase( );
463 myApp.setName( strAppName );
464 myApp.setUrl( strUrl );
465 myApp.setPassword( strPassword );
466 myApp.setCode( strCode );
467 myApp.setCodeHeading( strCodeHeading );
468 myApp.setData( strData );
469 myApp.setDataHeading( strDataHeading );
470 myApp.setDescription( strDescription );
471 myApp.setCodeCategory( strCodeCategory );
472 try
473 {
474 FileItem itemIcon = multiRequest.getFile( MyAppsDatabaseConstants.PARAMETER_MYAPP_ICON );
475
476 if ( itemIcon != null )
477 {
478 byte [ ] bytes = itemIcon.get( );
479 String strMimeType = itemIcon.getContentType( );
480 myApp.setIconContent( bytes );
481 myApp.setIconMimeType( strMimeType );
482 }
483 else
484 {
485 myApp.setIconContent( null );
486 myApp.setIconMimeType( null );
487 }
488
489 MyAppsDatabaseService.getInstance( ).create( myApp, getPlugin( ) );
490 }
491 catch( Exception e )
492 {
493 AppLogService.error( e.getMessage( ), e );
494 }
495
496 strJspUrl = getHomeUrl( request );
497 }
498 else
499 {
500 strJspUrl = strError;
501 }
502
503 return strJspUrl;
504 }
505
506
507
508
509
510
511
512
513
514
515 public String doModifyMyApp( HttpServletRequest request ) throws AccessDeniedException
516 {
517 String strJspUrl = StringUtils.EMPTY;
518 String strMyAppId = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID );
519
520 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
521 {
522 if ( !RBACService.isAuthorized( MyAppsDatabase.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID,
523 MyAppsDatabaseResourceIdService.PERMISSION_MODIFY_MYAPPS_DATABASE, getUser( ) ) )
524 {
525 throw new AccessDeniedException( );
526 }
527
528 String strAppName = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_NAME );
529 String strUrl = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_URL );
530 String strPassword = request.getParameter( MyAppsDatabaseConstants.PARAMETER_PASSWORD );
531 String strCode = request.getParameter( MyAppsDatabaseConstants.PARAMETER_CODE );
532 String strCodeHeading = request.getParameter( MyAppsDatabaseConstants.PARAMETER_CODE_HEADING );
533 String strData = request.getParameter( MyAppsDatabaseConstants.PARAMETER_DATA );
534 String strDataHeading = request.getParameter( MyAppsDatabaseConstants.PARAMETER_DATA_HEADING );
535 String strDescription = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_DESCRIPTION );
536 String strCodeCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
537 String strError = verifyFields( request );
538
539 if ( StringUtils.isBlank( strError ) )
540 {
541 int nMyAppId = Integer.parseInt( strMyAppId );
542
543
544 MultipartHttpServletRequest multiRequest = (MultipartHttpServletRequest) request;
545
546 MyAppsDatabase myApp = (MyAppsDatabase) MyAppsDatabaseService.getInstance( ).findByPrimaryKey( nMyAppId, getPlugin( ) );
547 myApp.setName( strAppName );
548 myApp.setUrl( strUrl );
549 myApp.setPassword( strPassword );
550 myApp.setCode( strCode );
551 myApp.setCodeHeading( strCodeHeading );
552 myApp.setData( strData );
553 myApp.setDataHeading( strDataHeading );
554 myApp.setDescription( strDescription );
555 myApp.setCodeCategory( strCodeCategory );
556 boolean bUpdateImage = ( multiRequest.getParameter( MyAppsDatabaseConstants.PARAMETER_UPDATE_FILE ) != null );
557
558 if ( bUpdateImage && ( multiRequest.getFile( MyAppsDatabaseConstants.PARAMETER_MYAPP_ICON ) != null ) )
559 {
560 try
561 {
562 FileItem itemIcon = multiRequest.getFile( MyAppsDatabaseConstants.PARAMETER_MYAPP_ICON );
563
564 if ( itemIcon != null )
565 {
566 byte [ ] bytes = itemIcon.get( );
567 String strMimeType = itemIcon.getContentType( );
568 myApp.setIconContent( bytes );
569 myApp.setIconMimeType( strMimeType );
570 }
571 }
572 catch( Exception e )
573 {
574 AppLogService.error( e.getMessage( ), e );
575 }
576 }
577
578 MyAppsDatabaseService.getInstance( ).update( myApp, bUpdateImage, getPlugin( ) );
579
580 strJspUrl = getHomeUrl( request );
581 }
582 else
583 {
584 strJspUrl = strError;
585 }
586 }
587 else
588 {
589 strJspUrl = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_ERROR, AdminMessage.TYPE_STOP );
590 }
591
592 return strJspUrl;
593 }
594
595
596
597
598
599
600
601
602 private String verifyFields( HttpServletRequest request )
603 {
604 String strError = StringUtils.EMPTY;
605 String strAppName = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_NAME );
606 String strUrl = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_URL );
607 String strPassword = request.getParameter( MyAppsDatabaseConstants.PARAMETER_PASSWORD );
608 String strCode = request.getParameter( MyAppsDatabaseConstants.PARAMETER_CODE );
609 String strCodeHeading = request.getParameter( MyAppsDatabaseConstants.PARAMETER_CODE_HEADING );
610 String strData = request.getParameter( MyAppsDatabaseConstants.PARAMETER_DATA );
611 String strDataHeading = request.getParameter( MyAppsDatabaseConstants.PARAMETER_DATA_HEADING );
612 String strDescription = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_DESCRIPTION );
613
614 if ( StringUtils.isBlank( strUrl ) || StringUtils.isBlank( strAppName ) )
615 {
616 strError = AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
617 }
618
619 if ( StringUtils.isBlank( strError ) )
620 {
621 if ( StringUtils.isNotBlank( strAppName ) && ( strAppName.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
622 {
623 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_NAME, getLocale( ) );
624 }
625
626 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strUrl )
627 && ( strUrl.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
628 {
629 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_URL, getLocale( ) );
630 }
631
632 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strPassword )
633 && ( strPassword.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
634 {
635 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_PASSWORD, getLocale( ) );
636 }
637
638 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strCode )
639 && ( strCode.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
640 {
641 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_USER_NAME, getLocale( ) );
642 }
643
644 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strCodeHeading )
645 && ( strCodeHeading.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
646 {
647 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_USER_HEADING, getLocale( ) );
648 }
649
650 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strData )
651 && ( strData.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
652 {
653 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_USER_FIELD, getLocale( ) );
654 }
655
656 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strDataHeading )
657 && ( strDataHeading.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
658 {
659 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_USER_FIELD_HEADING, getLocale( ) );
660 }
661
662 if ( StringUtils.isBlank( strError ) && StringUtils.isNotBlank( strDescription )
663 && ( strDescription.length( ) > MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT ) )
664 {
665 strError = I18nService.getLocalizedString( MyAppsDatabaseConstants.PROPERTY_LABEL_DESCRIPTION, getLocale( ) );
666 }
667
668 if ( StringUtils.isNotBlank( strError ) )
669 {
670 Object [ ] params = {
671 strError, MyAppsDatabaseConstants.PROPERTY_DEFAULT_FIELD_SIZE_INT
672 };
673 strError = AdminMessageService.getMessageUrl( request, MyAppsDatabaseConstants.MESSAGE_FIELD_TOO_LONG, params, AdminMessage.TYPE_STOP );
674 }
675 }
676
677 return strError;
678 }
679 }