View Javadoc
1   /*
2    * Copyright (c) 2002-2017, 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.updatercatalog.web;
35  
36  import fr.paris.lutece.plugins.updatercatalog.business.Catalog;
37  import fr.paris.lutece.plugins.updatercatalog.business.CatalogHome;
38  import fr.paris.lutece.plugins.updatercatalog.business.CatalogPlugin;
39  import fr.paris.lutece.plugins.updatercatalog.business.CatalogPluginEntry;
40  import fr.paris.lutece.plugins.updatercatalog.business.CatalogPluginHome;
41  import fr.paris.lutece.plugins.updatercatalog.business.PluginRelease;
42  import fr.paris.lutece.plugins.updatercatalog.business.PluginReleaseHome;
43  import fr.paris.lutece.plugins.updatercatalog.business.ReleaseUpgrade;
44  import fr.paris.lutece.plugins.updatercatalog.service.CatalogGenerationService;
45  import fr.paris.lutece.portal.service.message.AdminMessage;
46  import fr.paris.lutece.portal.service.message.AdminMessageService;
47  import fr.paris.lutece.portal.service.template.AppTemplateService;
48  import fr.paris.lutece.portal.web.admin.PluginAdminPageJspBean;
49  import fr.paris.lutece.portal.web.constants.Messages;
50  import fr.paris.lutece.util.html.HtmlTemplate;
51  import fr.paris.lutece.util.url.UrlItem;
52  
53  import java.util.ArrayList;
54  import java.util.Collections;
55  import java.util.HashMap;
56  import java.util.List;
57  
58  import javax.servlet.http.HttpServletRequest;
59  
60  
61  /**
62   * Catalog Jsp Bean
63   */
64  public class CatalogJspBean extends PluginAdminPageJspBean
65  {
66      /**
67       *
68       */
69      public static final String RIGHT_CATALOG_MANAGEMENT = "UPDATER_CATALOG_MANAGEMENT";
70  
71      // Templates
72      private static final String TEMPLATE_MANAGE_CATALOG = "admin/plugins/updatercatalog/manage_catalogs.html";
73      private static final String TEMPLATE_CREATE_CATALOG = "admin/plugins/updatercatalog/create_catalog.html";
74      private static final String TEMPLATE_MODIFY_CATALOG = "admin/plugins/updatercatalog/modify_catalog.html";
75      private static final String TEMPLATE_MANAGE_RELEASES = "admin/plugins/updatercatalog/manage_releases.html";
76      private static final String TEMPLATE_CREATE_RELEASE = "admin/plugins/updatercatalog/create_release.html";
77      private static final String TEMPLATE_MODIFY_RELEASE = "admin/plugins/updatercatalog/modify_release.html";
78      private static final String TEMPLATE_MANAGE_PLUGINS = "admin/plugins/updatercatalog/manage_plugins.html";
79      private static final String TEMPLATE_CREATE_PLUGIN = "admin/plugins/updatercatalog/create_plugin.html";
80      private static final String TEMPLATE_MODIFY_PLUGIN = "admin/plugins/updatercatalog/modify_plugin.html";
81      private static final String TEMPLATE_CREATE_UPGRADE = "admin/plugins/updatercatalog/create_upgrade.html";
82  
83      // Bookmarks
84      private static final String MARK_CATALOGS_LIST = "catalogs_list";
85      private static final String MARK_PLUGINS_LIST = "plugins_list";
86      private static final String MARK_CATALOG = "catalog";
87      private static final String MARK_AVAILABLE_PLUGINS = "available_plugins_list";
88      private static final String MARK_RELEASE = "release";
89      private static final String MARK_RELEASE_ID = "release_id";
90      private static final String MARK_PLUGIN = "plugin";
91  
92      // Parameters
93      private static final String PARAMETER_CATALOG_ID = "id_catalog";
94      private static final String PARAMETER_RELEASE_ID = "id_release";
95      private static final String PARAMETER_NAME = "name";
96      private static final String PARAMETER_DESCRIPTION = "description";
97      private static final String PARAMETER_LOCALE = "locale";
98      private static final String PARAMETER_OUTPUT_FILENAME = "output_filename";
99      private static final String PARAMETER_URL_REPOSITORY = "url_repository";
100     private static final String PARAMETER_VERSION = "version";
101     private static final String PARAMETER_URL_DOWNLOAD = "url_download";
102     private static final String PARAMETER_CORE_VERSION_MIN = "core_version_min";
103     private static final String PARAMETER_CORE_VERSION_MAX = "core_version_max";
104     private static final String PARAMETER_AUTHOR = "author";
105     private static final String PARAMETER_URL_HOMEPAGE = "url_homepage";
106     private static final String PARAMETER_CRITICAL = "critical";
107 
108     // JSP
109     private static final String JSP_EDIT_CATALOG = "EditCatalog.jsp";
110     private static final String JSP_DO_DELETE_CATALOG = "jsp/admin/plugins/updatercatalog/DoDeleteCatalog.jsp";
111     private static final String JSP_DO_DELETE_PLUGIN_RELEASE = "jsp/admin/plugins/updatercatalog/DoDeletePluginRelease.jsp";
112     private static final String JSP_DO_DELETE_PLUGIN = "jsp/admin/plugins/updatercatalog/DoDeletePlugin.jsp";
113     private static final String JSP_DO_DELETE_UPGRADE = "jsp/admin/plugins/updatercatalog/DoDeleteUpgrade.jsp";
114     private static final String JSP_MANAGE_PLUGINS_RELEASES = "ManagePluginsReleases.jsp";
115     private static final String JSP_MANAGE_PLUGINS = "ManagePlugins.jsp";
116     private static final String JSP_MODIFY_PLUGIN_RELEASE = "ModifyPluginRelease.jsp";
117 
118     // Messages 
119     private static final String MESSAGE_CATALOG_GENERATED = "updatercatalog.message.catalogGenerated";
120     private static final String MESSAGE_CONFIRM_DELETE_CATALOG = "updatercatalog.message.confirmDeleteCatalog";
121     private static final String MESSAGE_CONFIRM_DELETE_PLUGIN_RELEASE = "updatercatalog.message.confirmDeletePluginRelease";
122     private static final String MESSAGE_CONFIRM_DELETE_PLUGIN = "updatercatalog.message.confirmDeletePlugin";
123     private static final String MESSAGE_CONFIRM_DELETE_UPGRADE = "updatercatalog.message.confirmDeleteUpgrade";
124 
125     /**
126      * Provides the manage catalog page
127      * @param request The HTTP request
128      * @return The page
129      */
130     public String getManageCatalog( HttpServletRequest request )
131     {
132         List<Catalog> listCatalogs = CatalogHome.findAll(  );
133 
134         HashMap model = new HashMap(  );
135         model.put( MARK_CATALOGS_LIST, listCatalogs );
136 
137         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_CATALOG, getLocale(  ), model );
138 
139         return getAdminPage( template.getHtml(  ) );
140     }
141 
142     /**
143      * Returns The Edit page
144      * @param request The HTTP request
145      * @return The Edit page
146      */
147     public String getEditCatalog( HttpServletRequest request )
148     {
149         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
150         int nCatalogId = Integer.parseInt( strCatalogId );
151 
152         Catalog catalog = CatalogHome.findByPrimaryKey( nCatalogId );
153         List<CatalogPluginEntry> listEntries = CatalogHome.getPluginsEntries( nCatalogId );
154         List<CatalogPluginEntry> listPlugins = CatalogPluginHome.getAvailablePluginsByLocale( catalog.getLocale(  ) );
155         listPlugins = filterAlreadyInCatalog( listEntries, listPlugins );
156 
157         HashMap model = new HashMap(  );
158         model.put( MARK_CATALOG, catalog );
159         model.put( MARK_PLUGINS_LIST, listEntries );
160         model.put( MARK_AVAILABLE_PLUGINS, listPlugins );
161 
162         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_CATALOG, getLocale(  ), model );
163 
164         return getAdminPage( template.getHtml(  ) );
165     }
166 
167     /**
168      * Remove from the list all plugin already in the catalog
169      * @param listInCatalog The catalog's list of plugins
170      * @param listAll The list of all plugins
171      * @return The filtered list
172      */
173     private List<CatalogPluginEntry> filterAlreadyInCatalog( List<CatalogPluginEntry> listInCatalog,
174         List<CatalogPluginEntry> listAll )
175     {
176         List<CatalogPluginEntry> list = new ArrayList<CatalogPluginEntry>(  );
177 
178         for ( CatalogPluginEntry entry : listAll )
179         {
180             if ( !isInCatalog( entry.getPluginName(  ), listInCatalog ) )
181             {
182                 list.add( entry );
183             }
184         }
185 
186         return list;
187     }
188 
189     /**
190      * Tells weither the plugin is in the catalog or not
191      * @param strPluginName The plugin name
192      * @param listInCatalog The catalog's list of plugins
193      * @return true if the plugin is already in the catalog, otherwise false
194      */
195     private boolean isInCatalog( String strPluginName, List<CatalogPluginEntry> listInCatalog )
196     {
197         for ( CatalogPluginEntry entry : listInCatalog )
198         {
199             if ( entry.getPluginName(  ).equals( strPluginName ) )
200             {
201                 return true;
202             }
203         }
204 
205         return false;
206     }
207 
208     /**
209      * Add a release of a plugin in the catalog
210      * @param request The HTTP request
211      * @return The forward url
212      */
213     public String doCatalogAddRelease( HttpServletRequest request )
214     {
215         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
216         int nCatalogId = Integer.parseInt( strCatalogId );
217         String[] releases = request.getParameterValues( PARAMETER_RELEASE_ID );
218 
219         for ( int i = 0; i < releases.length; i++ )
220         {
221             int nReleaseId = Integer.parseInt( releases[i] );
222             CatalogHome.addRelease( nCatalogId, nReleaseId );
223         }
224 
225         UrlItem url = new UrlItem( JSP_EDIT_CATALOG );
226         url.addParameter( PARAMETER_CATALOG_ID, strCatalogId );
227 
228         return url.getUrl(  );
229     }
230 
231     /**
232      * Remove a plugin release from the catalog
233      * @param request The HTTP request
234      * @return The forward url
235      */
236     public String doCatalogRemoveRelease( HttpServletRequest request )
237     {
238         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
239         int nCatalogId = Integer.parseInt( strCatalogId );
240         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
241         int nReleaseId = Integer.parseInt( strReleaseId );
242         CatalogHome.removeRelease( nCatalogId, nReleaseId );
243 
244         UrlItem url = new UrlItem( JSP_EDIT_CATALOG );
245         url.addParameter( PARAMETER_CATALOG_ID, strCatalogId );
246 
247         return url.getUrl(  );
248     }
249 
250     /**
251      * Generate a catalog file
252      * @param request The HTTP request
253      * @return The forward url
254      */
255     public String doGenerateCatalog( HttpServletRequest request )
256     {
257         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
258         int nCatalogId = Integer.parseInt( strCatalogId );
259 
260         CatalogGenerationService.generateCatalog( nCatalogId );
261 
262         return AdminMessageService.getMessageUrl( request, MESSAGE_CATALOG_GENERATED, getHomeUrl( request ),
263             AdminMessage.TYPE_INFO );
264     }
265 
266     /**
267      * Provides the create catalog page
268      * @param request The HTTP request
269      * @return The page
270      */
271     public String getCreateCatalog( HttpServletRequest request )
272     {
273         HashMap model = new HashMap(  );
274 
275         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_CATALOG, getLocale(  ), model );
276 
277         return getAdminPage( template.getHtml(  ) );
278     }
279 
280     /**
281      * Create a new catalog
282      * @param request The HTTP request
283      * @return the forward url
284      */
285     public String doCreateCatalog( HttpServletRequest request )
286     {
287         Catalog catalog = new Catalog(  );
288         String strErrorUrl = getData( request, catalog );
289 
290         if ( strErrorUrl != null )
291         {
292             return strErrorUrl;
293         }
294 
295         CatalogHome.create( catalog );
296 
297         return getHomeUrl( request );
298     }
299 
300     /**
301      * Modify catalog's attributes
302      * @param request The HTTP request
303      * @return The forward url
304      */
305     public String doModifyCatalog( HttpServletRequest request )
306     {
307         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
308         int nCatalogId = Integer.parseInt( strCatalogId );
309 
310         Catalog catalog = CatalogHome.findByPrimaryKey( nCatalogId );
311         String strErrorUrl = getData( request, catalog );
312 
313         if ( strErrorUrl != null )
314         {
315             return strErrorUrl;
316         }
317 
318         CatalogHome.update( catalog );
319 
320         return getHomeUrl( request );
321     }
322 
323     /**
324      * Fills catalog infos from the request
325      * @param request The HTTP request
326      * @param catalog The catalog object to fill
327      * @return An ErrorUrl or null if no error
328      */
329     private String getData( HttpServletRequest request, Catalog catalog )
330     {
331         String strName = request.getParameter( PARAMETER_NAME );
332         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
333         String strLocale = request.getParameter( PARAMETER_LOCALE );
334         String strOutputFilename = request.getParameter( PARAMETER_OUTPUT_FILENAME );
335         String strUrlRepository = request.getParameter( PARAMETER_URL_REPOSITORY );
336 
337         if ( ( strName == null ) || ( strName.equals( "" ) ) || ( strDescription == null ) ||
338                 ( strDescription.equals( "" ) ) || ( strLocale == null ) || ( strLocale.equals( "" ) ) ||
339                 ( strOutputFilename == null ) || ( strOutputFilename.equals( "" ) ) || ( strUrlRepository == null ) ||
340                 ( strUrlRepository.equals( "" ) ) )
341         {
342             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
343         }
344 
345         catalog.setName( strName );
346         catalog.setDescription( strDescription );
347         catalog.setLocale( strLocale );
348         catalog.setOutputFilename( strOutputFilename );
349         catalog.setUrlRepository( strUrlRepository );
350 
351         return null;
352     }
353 
354     /**
355      * Confirm the catalog deletion
356      * @param request The HTTP request
357      * @return The forward url
358      */
359     public String deleteCatalog( HttpServletRequest request )
360     {
361         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
362         UrlItem url = new UrlItem( JSP_DO_DELETE_CATALOG );
363         url.addParameter( PARAMETER_CATALOG_ID, strCatalogId );
364 
365         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_CATALOG, url.getUrl(  ),
366             AdminMessage.TYPE_CONFIRMATION );
367     }
368 
369     /**
370      * Delete the catalog
371      * @param request The HTTP request
372      * @return The forward url
373      */
374     public String doDeleteCatalog( HttpServletRequest request )
375     {
376         String strCatalogId = request.getParameter( PARAMETER_CATALOG_ID );
377         int nCatalogId = Integer.parseInt( strCatalogId );
378 
379         CatalogHome.remove( nCatalogId );
380 
381         return getHomeUrl( request );
382     }
383 
384     /**
385      * Provides the manage catalog page
386      * @param request The HTTP request
387      * @return The page
388      */
389     public String getManagePluginsReleases( HttpServletRequest request )
390     {
391         List<PluginRelease> listPlugins = PluginReleaseHome.findAll(  );
392 
393         Collections.sort( listPlugins );
394 
395         HashMap model = new HashMap(  );
396         model.put( MARK_PLUGINS_LIST, listPlugins );
397 
398         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_RELEASES, getLocale(  ), model );
399 
400         return getAdminPage( template.getHtml(  ) );
401     }
402 
403     /**
404      * Provides the create plugin release page
405      * @param request The HTTP request
406      * @return The page
407      */
408     public String getCreatePluginRelease( HttpServletRequest request )
409     {
410         HashMap model = new HashMap(  );
411 
412         String strPluginName = request.getParameter( PARAMETER_NAME );
413         strPluginName = ( strPluginName == null ) ? "" : strPluginName;
414 
415         model.put( MARK_PLUGIN, strPluginName );
416         model.put( MARK_PLUGINS_LIST, CatalogPluginHome.getPlugins(  ) );
417 
418         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_RELEASE, getLocale(  ), model );
419 
420         return getAdminPage( template.getHtml(  ) );
421     }
422 
423     /**
424      * Create a new plugin release
425      * @param request The HTTP request
426      * @return the forward url
427      */
428     public String doCreatePluginRelease( HttpServletRequest request )
429     {
430         PluginRelease release = new PluginRelease(  );
431         String strErrorUrl = getPluginReleaseData( request, release );
432 
433         if ( strErrorUrl != null )
434         {
435             return strErrorUrl;
436         }
437 
438         PluginReleaseHome.create( release );
439 
440         return JSP_MANAGE_PLUGINS_RELEASES;
441     }
442 
443     /**
444      * Provides the modify plugin release page
445      * @param request The HTTP request
446      * @return The page
447      */
448     public String getModifyPluginRelease( HttpServletRequest request )
449     {
450         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
451         int nReleaseId = Integer.parseInt( strReleaseId );
452 
453         PluginRelease release = PluginReleaseHome.findByPrimaryKey( nReleaseId );
454         HashMap model = new HashMap(  );
455         model.put( MARK_RELEASE, release );
456 
457         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_RELEASE, getLocale(  ), model );
458 
459         return getAdminPage( template.getHtml(  ) );
460     }
461 
462     /**
463      * Create a new plugin release
464      * @param request The HTTP request
465      * @return the forward url
466      */
467     public String doModifyPluginRelease( HttpServletRequest request )
468     {
469         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
470         int nReleaseId = Integer.parseInt( strReleaseId );
471 
472         PluginRelease release = PluginReleaseHome.findByPrimaryKey( nReleaseId );
473         String strErrorUrl = getPluginReleaseData( request, release );
474 
475         if ( strErrorUrl != null )
476         {
477             return strErrorUrl;
478         }
479 
480         PluginReleaseHome.update( release );
481 
482         return JSP_MANAGE_PLUGINS_RELEASES;
483     }
484 
485     /**
486      * Gets Data from the request
487      * @param request the HTTP request
488      * @param release The release object to fill
489      * @return ErrorUrl or null if no error
490      */
491     private String getPluginReleaseData( HttpServletRequest request, PluginRelease release )
492     {
493         String strName = request.getParameter( PARAMETER_NAME );
494         String strVersion = request.getParameter( PARAMETER_VERSION );
495         String strUrlDownload = request.getParameter( PARAMETER_URL_DOWNLOAD );
496         String strCoreVersionMin = request.getParameter( PARAMETER_CORE_VERSION_MIN );
497         String strCoreVersionMax = request.getParameter( PARAMETER_CORE_VERSION_MAX );
498 
499         if ( ( strName == null ) || ( strName.equals( "" ) ) || ( strVersion == null ) || ( strVersion.equals( "" ) ) ||
500                 ( strUrlDownload == null ) || ( strUrlDownload.equals( "" ) ) || ( strCoreVersionMin == null ) ||
501                 ( strCoreVersionMin.equals( "" ) ) )
502         {
503             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
504         }
505 
506         release.setPluginName( strName );
507         release.setPluginVersion( strVersion );
508         release.setUrlDownload( strUrlDownload );
509         release.setCoreVersionMin( strCoreVersionMin );
510         release.setCoreVersionMax( strCoreVersionMax );
511 
512         return null;
513     }
514 
515     /**
516      * Confirm the release deletion
517      * @param request The HTTP request
518      * @return The forward url
519      */
520     public String deletePluginRelease( HttpServletRequest request )
521     {
522         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
523         UrlItem url = new UrlItem( JSP_DO_DELETE_PLUGIN_RELEASE );
524         url.addParameter( PARAMETER_RELEASE_ID, strReleaseId );
525 
526         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_PLUGIN_RELEASE, url.getUrl(  ),
527             AdminMessage.TYPE_CONFIRMATION );
528     }
529 
530     /**
531      * Delete the plugin release
532      * @param request The HTTP request
533      * @return The forward url
534      */
535     public String doDeletePluginRelease( HttpServletRequest request )
536     {
537         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
538         int nReleaseId = Integer.parseInt( strReleaseId );
539 
540         PluginReleaseHome.remove( nReleaseId );
541 
542         return JSP_MANAGE_PLUGINS_RELEASES;
543     }
544 
545     /**
546      * Provides the manage plugins page
547      * @param request The HTTP request
548      * @return The page
549      */
550     public String getManagePlugins( HttpServletRequest request )
551     {
552         List<CatalogPlugin> listPlugins = CatalogPluginHome.findAll(  );
553         Collections.sort( listPlugins );
554 
555         HashMap model = new HashMap(  );
556         model.put( MARK_PLUGINS_LIST, listPlugins );
557 
558         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_PLUGINS, getLocale(  ), model );
559 
560         return getAdminPage( template.getHtml(  ) );
561     }
562 
563     /**
564      * Provides the create plugin page
565      * @param request The HTTP request
566      * @return The page
567      */
568     public String getCreatePlugin( HttpServletRequest request )
569     {
570         HashMap model = new HashMap(  );
571 
572         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_PLUGIN, getLocale(  ), model );
573 
574         return getAdminPage( template.getHtml(  ) );
575     }
576 
577     /**
578      * Create a new plugin
579      * @param request The HTTP request
580      * @return the forward url
581      */
582     public String doCreatePlugin( HttpServletRequest request )
583     {
584         CatalogPlugin plugin = new CatalogPlugin(  );
585         String strErrorUrl = getPluginData( request, plugin );
586 
587         if ( strErrorUrl != null )
588         {
589             return strErrorUrl;
590         }
591 
592         CatalogPluginHome.create( plugin );
593 
594         return JSP_MANAGE_PLUGINS;
595     }
596 
597     /**
598      * Provides the modify plugin page
599      * @param request The HTTP request
600      * @return The page
601      */
602     public String getModifyPlugin( HttpServletRequest request )
603     {
604         String strPluginName = request.getParameter( PARAMETER_NAME );
605         String strLocale = request.getParameter( PARAMETER_LOCALE );
606 
607         CatalogPlugin plugin = CatalogPluginHome.findByPrimaryKey( strPluginName, strLocale );
608         HashMap model = new HashMap(  );
609         model.put( MARK_PLUGIN, plugin );
610 
611         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_PLUGIN, getLocale(  ), model );
612 
613         return getAdminPage( template.getHtml(  ) );
614     }
615 
616     /**
617      * Create a new plugin
618      * @param request The HTTP request
619      * @return the forward url
620      */
621     public String doModifyPlugin( HttpServletRequest request )
622     {
623         String strPluginName = request.getParameter( PARAMETER_NAME );
624         String strLocale = request.getParameter( PARAMETER_LOCALE );
625 
626         CatalogPlugin plugin = CatalogPluginHome.findByPrimaryKey( strPluginName, strLocale );
627         String strErrorUrl = getPluginData( request, plugin );
628 
629         if ( strErrorUrl != null )
630         {
631             return strErrorUrl;
632         }
633 
634         CatalogPluginHome.update( plugin );
635 
636         return JSP_MANAGE_PLUGINS;
637     }
638 
639     /** Gets Data from the request
640      * @param request the HTTP request
641      * @param plugin The plugin object to fill
642      * @return ErrorUrl or null if no error
643      */
644     private String getPluginData( HttpServletRequest request, CatalogPlugin plugin )
645     {
646         String strName = request.getParameter( PARAMETER_NAME );
647         String strLocale = request.getParameter( PARAMETER_LOCALE );
648         String strDescription = request.getParameter( PARAMETER_DESCRIPTION );
649         String strAuthor = request.getParameter( PARAMETER_AUTHOR );
650         String strUrlHomepage = request.getParameter( PARAMETER_URL_HOMEPAGE );
651 
652         if ( ( strName == null ) || ( strName.equals( "" ) ) || ( strLocale == null ) || ( strLocale.equals( "" ) ) ||
653                 ( strDescription == null ) || ( strDescription.equals( "" ) ) || ( strAuthor == null ) ||
654                 ( strAuthor.equals( "" ) ) || ( strUrlHomepage == null ) || ( strUrlHomepage.equals( "" ) ) )
655         {
656             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
657         }
658 
659         plugin.setPluginName( strName );
660         plugin.setPluginLocale( strLocale );
661         plugin.setPluginDescription( strDescription );
662         plugin.setPluginAuthor( strAuthor );
663         plugin.setUrlHomepage( strUrlHomepage );
664 
665         return null;
666     }
667 
668     /**
669      * Confirm the plugin deletion
670      * @param request The HTTP request
671      * @return The forward url
672      */
673     public String deletePlugin( HttpServletRequest request )
674     {
675         String strName = request.getParameter( PARAMETER_NAME );
676         String strLocale = request.getParameter( PARAMETER_LOCALE );
677         UrlItem url = new UrlItem( JSP_DO_DELETE_PLUGIN );
678         url.addParameter( PARAMETER_NAME, strName );
679         url.addParameter( PARAMETER_LOCALE, strLocale );
680 
681         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_PLUGIN, url.getUrl(  ),
682             AdminMessage.TYPE_CONFIRMATION );
683     }
684 
685     /**
686      * Delete the plugin
687      * @param request The HTTP request
688      * @return The forward url
689      */
690     public String doDeletePlugin( HttpServletRequest request )
691     {
692         String strName = request.getParameter( PARAMETER_NAME );
693         String strLocale = request.getParameter( PARAMETER_LOCALE );
694 
695         CatalogPluginHome.remove( strName, strLocale );
696 
697         return JSP_MANAGE_PLUGINS;
698     }
699 
700     /**
701      * Provides the create upgrade page
702      * @param request The HTTP request
703      * @return The page
704      */
705     public String getCreateUpgrade( HttpServletRequest request )
706     {
707         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
708 
709         HashMap model = new HashMap(  );
710         model.put( MARK_RELEASE_ID, strReleaseId );
711 
712         HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_CREATE_UPGRADE, getLocale(  ), model );
713 
714         return getAdminPage( template.getHtml(  ) );
715     }
716 
717     /**
718      * Create a new upgrade
719      * @param request The HTTP request
720      * @return the forward url
721      */
722     public String doCreateUpgrade( HttpServletRequest request )
723     {
724         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
725         int nReleaseId = Integer.parseInt( strReleaseId );
726 
727         ReleaseUpgrade upgrade = new ReleaseUpgrade(  );
728         String strErrorUrl = getUpgradeData( request, upgrade );
729 
730         if ( strErrorUrl != null )
731         {
732             return strErrorUrl;
733         }
734 
735         PluginReleaseHome.addUpgrade( nReleaseId, upgrade );
736 
737         UrlItem url = new UrlItem( JSP_MODIFY_PLUGIN_RELEASE );
738         url.addParameter( PARAMETER_RELEASE_ID, strReleaseId );
739 
740         return url.getUrl(  );
741     }
742 
743     /** Gets Data from the request
744      * @param request the HTTP request
745      * @param upgrade The upgrade object to fill
746      * @return ErrorUrl or null if no error
747      */
748     private String getUpgradeData( HttpServletRequest request, ReleaseUpgrade upgrade )
749     {
750         String strVersion = request.getParameter( PARAMETER_VERSION );
751         String strCritical = request.getParameter( PARAMETER_CRITICAL );
752         int nCritical = Integer.parseInt( strCritical );
753         String strUrlDownload = request.getParameter( PARAMETER_URL_DOWNLOAD );
754 
755         if ( ( strVersion == null ) || ( strVersion.equals( "" ) ) || ( strUrlDownload == null ) ||
756                 ( strUrlDownload.equals( "" ) ) )
757         {
758             return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
759         }
760 
761         upgrade.setVersionFrom( strVersion );
762         upgrade.setCritical( nCritical );
763         upgrade.setUrlDownload( strUrlDownload );
764 
765         return null;
766     }
767 
768     /**
769      * Confirm the upgrade deletion
770      * @param request The HTTP request
771      * @return The forward url
772      */
773     public String deleteUpgrade( HttpServletRequest request )
774     {
775         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
776         String strVersionFrom = request.getParameter( PARAMETER_VERSION );
777         UrlItem url = new UrlItem( JSP_DO_DELETE_UPGRADE );
778         url.addParameter( PARAMETER_RELEASE_ID, strReleaseId );
779         url.addParameter( PARAMETER_VERSION, strVersionFrom );
780 
781         return AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_DELETE_UPGRADE, url.getUrl(  ),
782             AdminMessage.TYPE_CONFIRMATION );
783     }
784 
785     /**
786      * Delete the upgrade release
787      * @param request The HTTP request
788      * @return The forward url
789      */
790     public String doDeleteUpgrade( HttpServletRequest request )
791     {
792         String strReleaseId = request.getParameter( PARAMETER_RELEASE_ID );
793         int nReleaseId = Integer.parseInt( strReleaseId );
794         String strVersionFrom = request.getParameter( PARAMETER_VERSION );
795 
796         PluginReleaseHome.deleteUpgrade( nReleaseId, strVersionFrom );
797 
798         UrlItem url = new UrlItem( JSP_MODIFY_PLUGIN_RELEASE );
799         url.addParameter( PARAMETER_RELEASE_ID, strReleaseId );
800 
801         return url.getUrl(  );
802     }
803 }