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.pluginwizard.web;
35
36 import fr.paris.lutece.plugins.pluginwizard.business.ConfigurationKey;
37 import fr.paris.lutece.plugins.pluginwizard.business.ConfigurationKeyHome;
38 import fr.paris.lutece.plugins.pluginwizard.business.ModelHome;
39 import fr.paris.lutece.plugins.pluginwizard.business.model.Application;
40 import fr.paris.lutece.plugins.pluginwizard.business.model.Attribute;
41 import fr.paris.lutece.plugins.pluginwizard.business.model.BusinessClass;
42 import fr.paris.lutece.plugins.pluginwizard.business.model.Feature;
43 import fr.paris.lutece.plugins.pluginwizard.business.model.PluginModel;
44 import fr.paris.lutece.plugins.pluginwizard.business.model.Portlet;
45 import fr.paris.lutece.plugins.pluginwizard.business.model.Rest;
46 import fr.paris.lutece.plugins.pluginwizard.service.MapperService;
47 import fr.paris.lutece.plugins.pluginwizard.service.ModelService;
48 import fr.paris.lutece.plugins.pluginwizard.service.QualityService;
49 import fr.paris.lutece.plugins.pluginwizard.service.generator.GeneratorService;
50 import fr.paris.lutece.plugins.pluginwizard.web.formbean.BusinessClassFormBean;
51 import fr.paris.lutece.plugins.pluginwizard.web.formbean.DescriptionFormBean;
52 import fr.paris.lutece.plugins.pluginwizard.web.formbean.PluginNameFormBean;
53 import fr.paris.lutece.portal.service.message.SiteMessageException;
54 import fr.paris.lutece.portal.service.plugin.Plugin;
55 import fr.paris.lutece.portal.service.security.UserNotSignedException;
56 import fr.paris.lutece.portal.service.util.AppPropertiesService;
57 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
58 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
59 import fr.paris.lutece.portal.util.mvc.utils.MVCMessageBox;
60 import fr.paris.lutece.portal.util.mvc.utils.MVCUtils;
61 import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
62 import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
63 import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
64 import fr.paris.lutece.portal.web.xpages.XPage;
65 import fr.paris.lutece.util.url.UrlItem;
66
67 import java.io.Serializable;
68 import java.nio.charset.StandardCharsets;
69 import java.util.ArrayList;
70 import java.util.Enumeration;
71 import java.util.List;
72 import java.util.Map;
73
74 import javax.servlet.http.HttpServletRequest;
75
76 import org.apache.commons.fileupload.FileItem;
77 import org.apache.commons.fileupload.FileUploadException;
78
79
80
81
82 @Controller( xpageName = "pluginwizard", pagePathI18nKey = "pluginwizard.pagePathLabel", pageTitleI18nKey = "pluginwizard.pageTitle" )
83 public class PluginWizardApp extends MVCApplication implements Serializable
84 {
85
86
87
88 private static final long serialVersionUID = 1L;
89
90 private static final String MARK_PLUGIN_ID = "plugin_id";
91 private static final String MARK_PLUGIN_MODEL = "plugin_model";
92
93
94 private static final String MARK_PLUGIN_PORTLETS = "plugin_portlets";
95 private static final String MARK_PLUGIN_APPLICATIONS = "plugin_applications";
96 private static final String MARK_PLUGIN_REST = "plugin_rest";
97 private static final String MARK_ADMIN_FEATURES = "admin_features";
98 private static final String MARK_BUSINESS_CLASSES = "business_classes";
99 private static final String MARK_BUSINESS_CLASS = "business_class";
100 private static final String MARK_BUSINESS_CLASS_ID = "business_class_id";
101 private static final String MARK_BUSINESS_CLASSES_COMBO = "combo_business_classes";
102 private static final String MARK_ATTRIBUTE_TYPE_COMBO = "combo_attribute_type";
103 private static final String MARK_SCHEMES_COMBO = "combo_schemes";
104 private static final String MARK_ATTRIBUTES_LIST = "attributes_list";
105
106
107 private static final String MARK_FEATURE = "feature";
108 private static final String MARK_ATTRIBUTE = "attribute";
109 private static final String MARK_APPLICATION = "application";
110 private static final String MARK_PORTLET = "portlet";
111 private static final String TEMPLATE_CREATE_PLUGIN = "/skin/plugins/pluginwizard/pluginwizard_create_plugin.html";
112 private static final String TEMPLATE_CREATE_PLUGIN_DESCRIPTION = "/skin/plugins/pluginwizard/pluginwizard_create_plugin_description.html";
113 private static final String TEMPLATE_MODIFY_PLUGIN_DESCRIPTION = "/skin/plugins/pluginwizard/pluginwizard_modify_plugin_description.html";
114 private static final String TEMPLATE_MODIFY_PLUGIN = "/skin/plugins/pluginwizard/pluginwizard_modify_plugin.html";
115 private static final String TEMPLATE_MODIFY_BUSINESS_CLASS = "/skin/plugins/pluginwizard/pluginwizard_modify_business_class.html";
116 private static final String TEMPLATE_MANAGE_ADMIN_FEATURES = "/skin/plugins/pluginwizard/pluginwizard_manage_admin_features.html";
117 private static final String TEMPLATE_MANAGE_PLUGIN_PORTLETS = "/skin/plugins/pluginwizard/pluginwizard_manage_portlets.html";
118 private static final String TEMPLATE_MANAGE_PLUGIN_APPLICATIONS = "/skin/plugins/pluginwizard/pluginwizard_manage_applications.html";
119 private static final String TEMPLATE_MANAGE_BUSINESS_CLASSES = "/skin/plugins/pluginwizard/pluginwizard_manage_business_classes.html";
120 private static final String TEMPLATE_MANAGE_REST = "/skin/plugins/pluginwizard/pluginwizard_manage_rest.html";
121 private static final String TEMPLATE_GET_RECAPITULATE = "/skin/plugins/pluginwizard/pluginwizard_plugin_recapitulate.html";
122
123
124 private static final String TEMPLATE_CREATE_ADMIN_FEATURE = "/skin/plugins/pluginwizard/pluginwizard_create_admin_feature.html";
125 private static final String TEMPLATE_CREATE_PLUGIN_PORTLET = "/skin/plugins/pluginwizard/pluginwizard_create_portlet.html";
126 private static final String TEMPLATE_CREATE_PLUGIN_APPLICATION = "/skin/plugins/pluginwizard/pluginwizard_create_application.html";
127 private static final String TEMPLATE_CREATE_BUSINESS_CLASS = "/skin/plugins/pluginwizard/pluginwizard_create_business_class.html";
128 private static final String TEMPLATE_CREATE_ATTRIBUTE = "/skin/plugins/pluginwizard/pluginwizard_create_attribute.html";
129
130
131 private static final String TEMPLATE_MODIFY_ATTRIBUTE = "/skin/plugins/pluginwizard/pluginwizard_modify_attribute.html";
132 private static final String TEMPLATE_MODIFY_ADMIN_FEATURE = "/skin/plugins/pluginwizard/pluginwizard_modify_admin_feature.html";
133 private static final String TEMPLATE_MODIFY_PLUGIN_PORTLET = "/skin/plugins/pluginwizard/pluginwizard_modify_portlet.html";
134 private static final String TEMPLATE_MODIFY_PLUGIN_APPLICATION = "/skin/plugins/pluginwizard/pluginwizard_modify_application.html";
135 private static final String TEMPLATE_MESSAGE_BOX_CONFIRMATION = "/skin/plugins/pluginwizard/message_confirmation.html";
136 private static final String TEMPLATE_MESSAGE_BOX_EXISTS = "/skin/plugins/pluginwizard/message_exists.html";
137 private static final String PARAM_ACTION = "action";
138 private static final String PARAM_PAGE = "page";
139 private static final String PARAM_FILE = "file";
140 private static final String PARAM_BUSINESS_CLASS_ID = "business_class_id";
141 private static final String PARAM_ATTRIBUTE_ID = "attribute_id";
142 private static final String PARAM_FEATURE_ID = "feature_id";
143 private static final String PARAM_APPLICATION_ID = "application_id";
144 private static final String PARAM_PORTLET_ID = "portletId";
145 private static final String PARAM_REFRESH = "refresh";
146 private static final String PARAM_ID_BUSINESS_CLASS = "id_business_class";
147
148
149 private static final String VIEW_CREATE_PLUGIN = "createPlugin";
150 private static final String VIEW_MODIFY_PLUGIN = "modifyPlugin";
151 private static final String VIEW_CREATE_DESCRIPTION = "createDescription";
152 private static final String VIEW_MODIFY_DESCRIPTION = "modifyDescription";
153 private static final String ACTION_CREATE_PLUGIN = "createPlugin";
154 private static final String ACTION_LOAD_PLUGIN = "loadPlugin";
155 private static final String ACTION_DESCRIPTION_PREVIOUS = "descriptionPrevious";
156 private static final String ACTION_DESCRIPTION_NEXT = "descriptionNext";
157 private static final String ACTION_RESET_DATA = "resetData";
158 private static final String PROPERTY_SEARCH_DUPLICATES = "pluginwizard.searchDuplicates";
159
160
161 private static final String VIEW_MANAGE_REST = "manageRest";
162 private static final String ACTION_MODIFY_REST_BACK = "modifyRestBack";
163 private static final String ACTION_MODIFY_REST_NEXT = "modifyRestNext";
164
165
166 private static final String VIEW_MANAGE_ADMIN_FEATURES = "manageAdminFeatures";
167 private static final String VIEW_CREATE_ADMIN_FEATURE = "createAdminFeature";
168 private static final String VIEW_MODIFY_ADMIN_FEATURE = "modifyAdminFeature";
169 private static final String ACTION_CREATE_ADMIN_FEATURE = "createAdminFeature";
170 private static final String ACTION_MODIFY_ADMIN_FEATURE = "modifyAdminFeature";
171 private static final String ACTION_CONFIRM_REMOVE_ADMIN_FEATURE = "confirmRemoveAdminFeature";
172 private static final String ACTION_REMOVE_ADMIN_FEATURE = "removeAdminFeature";
173 private static final String PROPERTY_CONFIRM_REMOVE_FEATURE_MESSAGE = "pluginwizard.siteMessage.confirmRemoveFeature.alertMessage";
174
175
176 private static final String VIEW_MANAGE_BUSINESS_CLASSES = "manageBusinessClasses";
177 private static final String VIEW_CREATE_BUSINESS_CLASS = "createBusinessClass";
178 private static final String VIEW_MODIFY_BUSINESS_CLASS = "modifyBusinessClass";
179 private static final String ACTION_CREATE_BUSINESS_CLASS = "createBusinessClass";
180 private static final String ACTION_MODIFY_BUSINESS_CLASS = "modifyBusinessClass";
181 private static final String ACTION_CONFIRM_REMOVE_BUSINESS_CLASS = "confirmRemoveBusinessClass";
182 private static final String ACTION_REMOVE_BUSINESS_CLASS = "removeBusinessClass";
183 private static final String PROPERTY_CONFIRM_REMOVE_BUSINESS_CLASS_MESSAGE = "pluginwizard.siteMessage.confirmRemoveBusinessClass.title";
184
185
186 private static final String VIEW_CREATE_ATTRIBUTE = "createAttribute";
187 private static final String VIEW_MODIFY_ATTRIBUTE = "modifyAttribute";
188 private static final String ACTION_CREATE_ATTRIBUTE = "createAttribute";
189 private static final String ACTION_MODIFY_ATTRIBUTE = "modifyAttribute";
190 private static final String ACTION_CONFIRM_REMOVE_ATTRIBUTE = "confirmRemoveAttribute";
191 private static final String ACTION_REMOVE_ATTRIBUTE = "removeAttribute";
192 private static final String ACTION_VALIDATE_ATTRIBUTES = "validateAttributes";
193 private static final String PROPERTY_CONFIRM_REMOVE_ATTRIBUTE_MESSAGE = "pluginwizard.siteMessage.confirmRemoveAttribute.alertMessage";
194
195
196 private static final String VIEW_MANAGE_APPLICATIONS = "manageApplications";
197 private static final String VIEW_CREATE_APPLICATION = "createApplication";
198 private static final String VIEW_MODIFY_APPLICATION = "modifyApplication";
199 private static final String ACTION_CREATE_APPLICATION = "createApplication";
200 private static final String ACTION_MODIFY_APPLICATION = "modifyApplication";
201 private static final String ACTION_CONFIRM_REMOVE_APPLICATION = "confirmRemoveApplication";
202 private static final String ACTION_REMOVE_APPLICATION = "removeApplication";
203 private static final String PROPERTY_CONFIRM_REMOVE_APPLICATION_MESSAGE = "pluginwizard.siteMessage.confirmRemoveApplication.title";
204
205
206 private static final String VIEW_MANAGE_PORTLETS = "managePortlets";
207 private static final String VIEW_CREATE_PORTLET = "createPortlet";
208 private static final String VIEW_MODIFY_PORTLET = "modifyPortlet";
209 private static final String ACTION_CREATE_PORTLET = "createPortlet";
210 private static final String ACTION_MODIFY_PORTLET = "modifyPortlet";
211 private static final String ACTION_CONFIRM_REMOVE_PORTLET = "confirmRemovePortlet";
212 private static final String ACTION_REMOVE_PORTLET = "removePortlet";
213 private static final String PROPERTY_CONFIRM_REMOVE_PORTLET_MESSAGE = "pluginwizard.siteMessage.confirmRemovePortlet.alertMessage";
214
215
216 private static final String VIEW_RECAPITULATE = "recapitulate";
217 private static final String JSP_PAGE_PORTAL = "jsp/site/Portal.jsp";
218 private static final String PLUGIN_NAME = "pluginwizard";
219
220
221 public static final String ERROR_TABLE_PREFIX = "pluginwizard.error.attribute.tablePrefix";
222 public static final String ERROR_PRIMARY_TYPE = "pluginwizard.error.attribute.primaryType";
223 public static final String ERROR_DESCRIPTION_TYPE = "pluginwizard.error.attribute.descriptionType";
224 public static final String ERROR_LOAD_PLUGIN = "pluginwizard.error.plugin.file";
225 public static final String ERROR_MODULE_NAME = "pluginwizard.error.module.name.pattern";
226 public static final String ERROR_PLUGIN_NAME = "pluginwizard.error.plugin.name.pattern";
227 public static final String ERROR_FEATURE_DUPLICATE = "pluginwizard.error.feature.right.duplicate";
228
229
230 public static final String INFO_SESSION_EXPIRED = "pluginwizard.info.sessionExpired";
231 public static final String INFO_PLUGIN_CREATED = "pluginwizard.info.pluginCreated";
232 public static final String INFO_DATA_RESET = "pluginwizard.info.dataReset";
233 public static final String INFO_FEATURE_CREATED = "pluginwizard.info.feature.created";
234 public static final String INFO_FEATURE_UPDATED = "pluginwizard.info.feature.updated";
235 public static final String INFO_FEATURE_DELETED = "pluginwizard.info.feature.deleted";
236 public static final String INFO_BUSINESS_CLASS_CREATED = "pluginwizard.info.businessClass.created";
237 public static final String INFO_BUSINESS_CLASS_UPDATED = "pluginwizard.info.businessClass.updated";
238 public static final String INFO_BUSINESS_CLASS_DELETED = "pluginwizard.info.businessClass.deleted";
239 public static final String INFO_ATTRIBUTE_CREATED = "pluginwizard.info.attribute.created";
240 public static final String INFO_ATTRIBUTE_UPDATED = "pluginwizard.info.attribute.updated";
241 public static final String INFO_ATTRIBUTE_DELETED = "pluginwizard.info.attribute.deleted";
242 public static final String INFO_APPLICATION_CREATED = "pluginwizard.info.application.created";
243 public static final String INFO_APPLICATION_UPDATED = "pluginwizard.info.application.updated";
244 public static final String INFO_APPLICATION_DELETED = "pluginwizard.info.application.deleted";
245 public static final String INFO_PORTLET_CREATED = "pluginwizard.info.portlet.created";
246 public static final String INFO_PORTLET_UPDATED = "pluginwizard.info.portlet.updated";
247 public static final String INFO_PORTLET_DELETED = "pluginwizard.info.portlet.deleted";
248 private int _nPluginId;
249 private String _strPluginName;
250 private DescriptionFormBean _description;
251 private Feature _feature;
252 private BusinessClassFormBean _businessClass;
253 private Attribute _attribute;
254 private Application _application;
255 private Portlet _portlet;
256 private Rest _rest;
257
258
259
260
261 @Override
262 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin ) throws SiteMessageException, UserNotSignedException
263 {
264 if ( _nPluginId == 0 )
265 {
266 String strAction = MVCUtils.getAction( request );
267 String strView = MVCUtils.getView( request );
268
269 if ( !ACTION_LOAD_PLUGIN.equals( strAction ) && !ACTION_CREATE_PLUGIN.equals( strAction ) && !VIEW_CREATE_PLUGIN.equals( strView ) )
270 {
271 if ( ( strAction != null ) || ( strView != null ) )
272 {
273 addInfo( INFO_SESSION_EXPIRED, getLocale( request ) );
274 }
275
276 return getCreatePlugin( request );
277 }
278 }
279
280 return super.getPage( request, nMode, plugin );
281 }
282
283
284
285
286
287
288
289
290
291
292
293 @View( value = VIEW_CREATE_PLUGIN, defaultView = true )
294 public XPage getCreatePlugin( HttpServletRequest request )
295 {
296 return getXPage( TEMPLATE_CREATE_PLUGIN, getLocale( request ) );
297 }
298
299
300
301
302
303
304
305
306 @View( VIEW_MODIFY_PLUGIN )
307 public XPage getModifyPlugin( HttpServletRequest request )
308 {
309 return getXPage( TEMPLATE_MODIFY_PLUGIN, getLocale( request ), getPluginModel( ) );
310 }
311
312
313
314
315
316
317
318
319 @Action( ACTION_CREATE_PLUGIN )
320 public XPage doCreatePlugin( HttpServletRequest request )
321 {
322 PluginNameFormBeanzard/web/formbean/PluginNameFormBean.html#PluginNameFormBean">PluginNameFormBean form = new PluginNameFormBean( );
323 populate( form, request );
324
325 if ( !validateBean( form, getLocale( request ) ) )
326 {
327 return redirectView( request, VIEW_CREATE_PLUGIN );
328 }
329
330 _strPluginName = form.getName( );
331
332
333 if ( AppPropertiesService.getPropertyBoolean( PROPERTY_SEARCH_DUPLICATES, false ) )
334 {
335 _nPluginId = ModelHome.exists( form.getName( ) );
336 }
337 else
338 {
339 _nPluginId = -1;
340 }
341
342 if ( _nPluginId == -1 )
343 {
344
345 addInfo( INFO_PLUGIN_CREATED, getLocale( request ) );
346 _nPluginId = ModelService.createModel( form.getName( ) );
347
348 return redirectView( request, VIEW_CREATE_DESCRIPTION );
349 }
350
351 return redirectMessageBox( request, buildExistsMessageBox( ) );
352 }
353
354
355
356
357
358
359
360
361
362 @Action( ACTION_LOAD_PLUGIN )
363 public XPage doLoadPlugin( HttpServletRequest request ) throws FileUploadException
364 {
365 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
366 FileItem fileItem = multipartRequest.getFile( PARAM_FILE );
367
368 if ( fileItem.getName( ) == null || fileItem.getName( ).isEmpty( ) )
369 {
370 addError( ERROR_LOAD_PLUGIN, getLocale( request ) );
371 return redirectView( request, VIEW_CREATE_PLUGIN );
372 }
373
374 String strJson = new String( fileItem.get( ), StandardCharsets.UTF_8 );
375 PluginModel pluginModel = MapperService.readJson( strJson );
376
377 _nPluginId = ModelService.savePluginModelFromJson( pluginModel );
378 _description = ModelService.getDescription( _nPluginId );
379 _strPluginName = ( "MODULE".equals( pluginModel.getType( ) ) ? pluginModel.getModuleName( ) : pluginModel.getPluginName( ) );
380
381 return redirectView( request, VIEW_MODIFY_DESCRIPTION );
382 }
383
384 @Action( ACTION_RESET_DATA )
385 public XPage doResetData( HttpServletRequest request )
386 {
387 ModelService.removeAll( _nPluginId );
388 addInfo( INFO_DATA_RESET, getLocale( request ) );
389
390 return redirectView( request, VIEW_CREATE_DESCRIPTION );
391 }
392
393
394
395
396
397
398
399
400
401
402
403 @View( VIEW_CREATE_DESCRIPTION )
404 public XPage getCreatePluginDescription( HttpServletRequest request )
405 {
406 Map<String, Object> model = getPluginModel( );
407
408 _description = new DescriptionFormBean( );
409
410 for ( ConfigurationKey key : ConfigurationKeyHome.getConfigurationKeysList( ) )
411 {
412 model.put( key.getKeyDescription( ).trim( ), key.getKeyValue( ) );
413 }
414
415 model.put( MARK_PLUGIN_ID, _nPluginId );
416
417 return getXPage( TEMPLATE_CREATE_PLUGIN_DESCRIPTION, getLocale( request ), model );
418 }
419
420
421
422
423
424
425
426
427 @View( VIEW_MODIFY_DESCRIPTION )
428 public XPage getModifyPluginDescription( HttpServletRequest request )
429 {
430 Map<String, Object> model = getPluginModel( );
431 _description = ( _description != null ) ? _description : ModelService.getDescription( _nPluginId );
432 model.put( MARK_PLUGIN_MODEL, _description );
433
434 return getXPage( TEMPLATE_MODIFY_PLUGIN_DESCRIPTION, getLocale( request ), model );
435 }
436
437
438
439
440
441
442
443
444 @Action( ACTION_DESCRIPTION_PREVIOUS )
445 public XPage doDescritionPrevious( HttpServletRequest request )
446 {
447 return doModifyPlugin( request, VIEW_CREATE_PLUGIN );
448 }
449
450
451
452
453
454
455
456
457 @Action( ACTION_DESCRIPTION_NEXT )
458 public XPage doDescritionNext( HttpServletRequest request )
459 {
460 return doModifyPlugin( request, VIEW_MANAGE_BUSINESS_CLASSES );
461 }
462
463
464
465
466
467
468
469
470
471
472 private XPage doModifyPlugin( HttpServletRequest request, String strView )
473 {
474 populate( _description, request );
475
476 if ( _description.getPluginName( ).contains( "-" ) )
477 {
478 if ( !_description.getPluginName( ).matches( "[a-z]*-[a-z]*" ) )
479 {
480 addError( ERROR_MODULE_NAME, getLocale( request ) );
481 return redirectView( request, VIEW_MODIFY_DESCRIPTION );
482 }
483 _description.setModule( true );
484 }
485 else
486 {
487 if ( !_description.getPluginName( ).matches( "[a-z]*" ) )
488 {
489 addError( ERROR_PLUGIN_NAME, getLocale( request ) );
490 return redirectView( request, VIEW_MODIFY_DESCRIPTION );
491 }
492 _description.setModule( false );
493 }
494
495 if ( !validateBean( _description, getLocale( request ) ) )
496 {
497 return redirectView( request, VIEW_MODIFY_DESCRIPTION );
498 }
499
500 _description.setPluginClass( "fr.paris.lutece.portal.service.plugin.PluginDefaultImplementation" );
501 _description.setPluginIconUrl( "images/admin/skin/feature_default_icon.png" );
502
503 ModelService.updateDescription( _nPluginId, _description );
504
505 return redirectView( request, strView );
506 }
507
508
509
510
511
512
513
514
515
516
517 @View( VIEW_MANAGE_ADMIN_FEATURES )
518 public XPage getManageAdminFeatures( HttpServletRequest request )
519 {
520 PluginModel pm = ModelService.getPluginModel( _nPluginId );
521
522 Map<String, Object> model = getModel( );
523
524 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
525 model.put( MARK_ADMIN_FEATURES, pm.getFeatures( ) );
526
527 return getXPage( TEMPLATE_MANAGE_ADMIN_FEATURES, getLocale( request ), model );
528 }
529
530
531
532
533
534
535
536
537 @View( VIEW_CREATE_ADMIN_FEATURE )
538 public XPage getCreateAdminFeature( HttpServletRequest request )
539 {
540 PluginModel pm = ModelService.getPluginModel( _nPluginId );
541 _feature = ( _feature != null ) ? _feature : new Feature( );
542
543 Map<String, Object> model = getPluginModel( );
544 model.put( MARK_ADMIN_FEATURES, pm.getFeatures( ) );
545 model.put( MARK_FEATURE, _feature );
546 model.put( MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses( _nPluginId ) );
547
548 return getXPage( TEMPLATE_CREATE_ADMIN_FEATURE, getLocale( request ), model );
549 }
550
551
552
553
554
555
556
557
558 @View( VIEW_MODIFY_ADMIN_FEATURE )
559 public XPage getModifyAdminFeature( HttpServletRequest request )
560 {
561 PluginModel pm = ModelService.getPluginModel( _nPluginId );
562 int nFeatureId = Integer.parseInt( request.getParameter( PARAM_FEATURE_ID ) );
563
564 if ( ( _feature == null ) || ( _feature.getId( ) != nFeatureId ) )
565 {
566 _feature = ModelService.getFeature( _nPluginId, nFeatureId );
567 }
568
569 Map<String, Object> model = getModel( );
570 model.put( MARK_FEATURE, _feature );
571 model.put( MARK_ADMIN_FEATURES, pm.getFeatures( ) );
572 model.put( MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses( _nPluginId ) );
573
574 return getXPage( TEMPLATE_MODIFY_ADMIN_FEATURE, getLocale( request ), model );
575 }
576
577
578
579
580
581
582
583
584 @Action( ACTION_CREATE_ADMIN_FEATURE )
585 public XPage doCreateAdminFeature( HttpServletRequest request )
586 {
587 populate( _feature, request );
588
589 List<Integer> listBusinessClasses = getBusinessClasses( request );
590 _feature.setIdBusinessClasses( listBusinessClasses );
591
592 if ( !validateBean( _feature, getLocale( request ) ) )
593 {
594 return redirectView( request, VIEW_CREATE_ADMIN_FEATURE );
595 }
596
597 else if ( QualityService.existsDuplicateFeatureRight( _feature, ModelService.getPluginModel(_nPluginId).getFeatures()))
598 {
599 addError(ERROR_FEATURE_DUPLICATE, getLocale( request ));
600 return redirectView( request, VIEW_CREATE_ADMIN_FEATURE );
601 }
602
603 else
604 {
605 ModelService.addFeature( _nPluginId, _feature );
606 _feature = null;
607 addInfo( INFO_FEATURE_CREATED, getLocale( request ) );
608
609 return redirectView( request, VIEW_MANAGE_ADMIN_FEATURES );
610 }
611 }
612
613
614
615
616
617
618
619
620 @Action( ACTION_MODIFY_ADMIN_FEATURE )
621 public XPage doModifyAdminFeature( HttpServletRequest request )
622 {
623 populate( _feature, request );
624
625 List<Integer> listBusinessClasses = getBusinessClasses( request );
626 _feature.setIdBusinessClasses( listBusinessClasses );
627
628 if ( !validateBean( _feature, getLocale( request ) ) )
629 {
630 return redirect( request, VIEW_MODIFY_ADMIN_FEATURE, PARAM_FEATURE_ID, _feature.getId( ) );
631 }
632
633 else if ( QualityService.existsDuplicateFeatureRight( _feature, ModelService.getPluginModel(_nPluginId).getFeatures()))
634 {
635 addError(ERROR_FEATURE_DUPLICATE, getLocale( request ));
636 return redirect( request, VIEW_MODIFY_ADMIN_FEATURE, PARAM_FEATURE_ID, _feature.getId( ) );
637 }
638
639 else
640 {
641 ModelService.updateFeature( _nPluginId, _feature );
642 _feature = null;
643 addInfo( INFO_FEATURE_UPDATED, getLocale( request ) );
644
645 return redirectView( request, VIEW_MANAGE_ADMIN_FEATURES );
646 }
647 }
648
649
650
651
652
653
654
655
656 @Action( ACTION_CONFIRM_REMOVE_ADMIN_FEATURE )
657 public XPage doConfirmRemoveAdminFeature( HttpServletRequest request )
658 {
659 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
660
661 url.addParameter( PARAM_PAGE, PLUGIN_NAME );
662 url.addParameter( PARAM_ACTION, ACTION_REMOVE_ADMIN_FEATURE );
663 url.addParameter( PARAM_FEATURE_ID, request.getParameter( PARAM_FEATURE_ID ) );
664
665 return redirectMessageBox( request,
666 buildConfirmMessageBox( PROPERTY_CONFIRM_REMOVE_FEATURE_MESSAGE, url.getUrl( ), getViewFullUrl( VIEW_MANAGE_ADMIN_FEATURES ) ) );
667 }
668
669
670
671
672
673
674
675
676 @Action( ACTION_REMOVE_ADMIN_FEATURE )
677 public XPage doRemoveAdminFeature( HttpServletRequest request )
678 {
679 int nFeatureId = Integer.parseInt( request.getParameter( PARAM_FEATURE_ID ) );
680 ModelService.removeFeature( _nPluginId, nFeatureId );
681 addInfo( INFO_FEATURE_DELETED, getLocale( request ) );
682
683 return redirectView( request, VIEW_MANAGE_ADMIN_FEATURES );
684 }
685
686
687
688
689
690
691
692
693
694
695 @View( VIEW_MANAGE_BUSINESS_CLASSES )
696 public XPage getManageBusinessClasses( HttpServletRequest request )
697 {
698 Map<String, Object> model = getModel( );
699 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
700 model.put( MARK_BUSINESS_CLASSES, ModelService.getPluginModel( _nPluginId ).getBusinessClasses( ) );
701
702 return getXPage( TEMPLATE_MANAGE_BUSINESS_CLASSES, getLocale( request ), model );
703 }
704
705
706
707
708
709
710
711
712 @View( VIEW_CREATE_BUSINESS_CLASS )
713 public XPage getCreateBusinessClass( HttpServletRequest request )
714 {
715 _businessClass = ( _businessClass != null ) ? _businessClass : new BusinessClassFormBean( );
716
717 Map<String, Object> model = getPluginModel( );
718
719 model.put( MARK_BUSINESS_CLASS, _businessClass );
720
721 return getXPage( TEMPLATE_CREATE_BUSINESS_CLASS, getLocale( request ), model );
722 }
723
724
725
726
727
728
729
730
731 @View( VIEW_MODIFY_BUSINESS_CLASS )
732 public XPage getModifyBusinessClass( HttpServletRequest request )
733 {
734 int nBusinessClassId = Integer.parseInt( request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
735 String strRefresh = request.getParameter( PARAM_REFRESH );
736
737 if ( ( _businessClass == null ) || ( _businessClass.getId( ) != nBusinessClassId ) || ( strRefresh != null ) )
738 {
739 _businessClass = ModelService.getFormBusinessClass( _nPluginId, nBusinessClassId );
740 }
741
742 _attribute = null;
743
744 Map<String, Object> model = getPluginModel( );
745 model.put( MARK_BUSINESS_CLASS, _businessClass );
746 model.put( MARK_ATTRIBUTES_LIST, ModelService.getBusinessClass( _nPluginId, nBusinessClassId ).getAttributes( ) );
747
748 return getXPage( TEMPLATE_MODIFY_BUSINESS_CLASS, getLocale( request ), model );
749 }
750
751
752
753
754
755
756
757
758 @Action( ACTION_CREATE_BUSINESS_CLASS )
759 public XPage doCreateBusinessClass( HttpServletRequest request )
760 {
761 populate( _businessClass, request );
762
763 boolean bValidateBean = validateBean( _businessClass, getLocale( request ) );
764 boolean bValidateTablePrefix = validateTablePrefix( request, _businessClass );
765 boolean bValid = bValidateBean && bValidateTablePrefix;
766
767 if ( !bValid )
768 {
769 return redirectView( request, VIEW_CREATE_BUSINESS_CLASS );
770 }
771
772 BusinessClass businessClass = ModelService.addBusinessClass( _nPluginId, _businessClass );
773 _businessClass = null;
774 addInfo( INFO_BUSINESS_CLASS_CREATED, getLocale( request ) );
775
776 return redirect( request, VIEW_MODIFY_BUSINESS_CLASS, PARAM_BUSINESS_CLASS_ID, businessClass.getId( ) );
777 }
778
779
780
781
782
783
784
785
786 @Action( ACTION_MODIFY_BUSINESS_CLASS )
787 public XPage doModifyBusinessClass( HttpServletRequest request )
788 {
789 populate( _businessClass, request );
790
791 boolean bValidateBean = validateBean( _businessClass, getLocale( request ) );
792 boolean bValidateTablePrefix = validateTablePrefix( request, _businessClass );
793 boolean bValid = bValidateBean && bValidateTablePrefix;
794
795 if ( !bValid )
796 {
797 return redirect( request, VIEW_MODIFY_BUSINESS_CLASS, PARAM_BUSINESS_CLASS_ID, _businessClass.getId( ) );
798 }
799
800 ModelService.updateBusinessClass( _nPluginId, _businessClass );
801 _businessClass = null;
802 addInfo( INFO_BUSINESS_CLASS_UPDATED, getLocale( request ) );
803
804 return redirectView( request, VIEW_MANAGE_BUSINESS_CLASSES );
805 }
806
807
808
809
810
811
812
813
814
815
816 private boolean validateTablePrefix( HttpServletRequest request, BusinessClassFormBean businessClass )
817 {
818 String strTablePrefix = _strPluginName.replace( "-", "_" ) + "_";
819 boolean bValidate = businessClass.getBusinessTableName( ).startsWith( strTablePrefix );
820
821 if ( !bValidate )
822 {
823 addError( ERROR_TABLE_PREFIX, getLocale( request ) );
824 }
825
826 return bValidate;
827 }
828
829
830
831
832
833
834
835
836 @Action( ACTION_CONFIRM_REMOVE_BUSINESS_CLASS )
837 public XPage doConfirmRemoveBusinessClass( HttpServletRequest request )
838 {
839 String strBusinessClassId = request.getParameter( PARAM_BUSINESS_CLASS_ID );
840 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
841 url.addParameter( PARAM_PAGE, PLUGIN_NAME );
842 url.addParameter( PARAM_ACTION, ACTION_REMOVE_BUSINESS_CLASS );
843 url.addParameter( PARAM_BUSINESS_CLASS_ID, strBusinessClassId );
844 url.addParameter( PARAM_FEATURE_ID, request.getParameter( PARAM_FEATURE_ID ) );
845
846 return redirectMessageBox( request,
847 buildConfirmMessageBox( PROPERTY_CONFIRM_REMOVE_BUSINESS_CLASS_MESSAGE, url.getUrl( ), getViewFullUrl( VIEW_MANAGE_BUSINESS_CLASSES ) ) );
848 }
849
850
851
852
853
854
855
856
857 @Action( ACTION_REMOVE_BUSINESS_CLASS )
858 public XPage doRemoveBusinessClass( HttpServletRequest request )
859 {
860 int nBusinessClassId = Integer.parseInt( request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
861
862 ModelService.removeBusinessClass( _nPluginId, nBusinessClassId );
863 addInfo( INFO_BUSINESS_CLASS_DELETED, getLocale( request ) );
864
865 return redirectView( request, VIEW_MANAGE_BUSINESS_CLASSES );
866 }
867
868
869
870
871
872
873
874
875
876
877
878 @View( VIEW_CREATE_ATTRIBUTE )
879 public XPage getCreateAttribute( HttpServletRequest request )
880 {
881 String strBusinessClassId = request.getParameter( PARAM_BUSINESS_CLASS_ID );
882
883 if ( _attribute == null )
884 {
885 _attribute = new Attribute( );
886 }
887
888 Map<String, Object> model = getModel( );
889 model.put( MARK_BUSINESS_CLASS_ID, strBusinessClassId );
890 model.put( MARK_ATTRIBUTE_TYPE_COMBO, ModelService.getAttributeTypes( getLocale( request ) ) );
891 model.put( MARK_ATTRIBUTE, _attribute );
892
893 return getXPage( TEMPLATE_CREATE_ATTRIBUTE, getLocale( request ), model );
894 }
895
896
897
898
899
900
901
902
903 @View( VIEW_MODIFY_ATTRIBUTE )
904 public XPage getModifyAttribute( HttpServletRequest request )
905 {
906 Map<String, Object> model = getModel( );
907 int nIdBusinessClass = Integer.parseInt( request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
908 int nIdAttribute = Integer.parseInt( request.getParameter( PARAM_ATTRIBUTE_ID ) );
909
910 if ( ( _attribute == null ) || ( _attribute.getId( ) != nIdAttribute ) )
911 {
912 _attribute = ModelService.getAttribute( _nPluginId, nIdBusinessClass, nIdAttribute );
913 }
914
915 model.put( MARK_PLUGIN_ID, _nPluginId );
916 model.put( MARK_BUSINESS_CLASS_ID, nIdBusinessClass );
917 model.put( MARK_ATTRIBUTE_TYPE_COMBO, ModelService.getAttributeTypes( getLocale( request ) ) );
918 model.put( MARK_ATTRIBUTE, _attribute );
919
920 return getXPage( TEMPLATE_MODIFY_ATTRIBUTE, getLocale( request ), model );
921 }
922
923
924
925
926
927
928
929
930 @Action( ACTION_CREATE_ATTRIBUTE )
931 public XPage doCreateAttribute( HttpServletRequest request )
932 {
933 int nBusinessClassId = Integer.parseInt( request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
934 populate( _attribute, request );
935
936 if ( !validateBean( _attribute, getLocale( request ) ) )
937 {
938 return redirect( request, VIEW_CREATE_ATTRIBUTE, PARAM_BUSINESS_CLASS_ID, nBusinessClassId, PARAM_ATTRIBUTE_ID, _attribute.getId( ) );
939 }
940
941 ModelService.addAttribute( _nPluginId, nBusinessClassId, _attribute );
942 _attribute = null;
943 addInfo( INFO_ATTRIBUTE_CREATED, getLocale( request ) );
944
945 return redirect( request, VIEW_MODIFY_BUSINESS_CLASS, PARAM_BUSINESS_CLASS_ID, nBusinessClassId, PARAM_REFRESH, 1 );
946 }
947
948
949
950
951
952
953
954
955 @Action( ACTION_MODIFY_ATTRIBUTE )
956 public XPage doModifyAttribute( HttpServletRequest request )
957 {
958 int nBusinessClassId = Integer.parseInt( request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
959
960 _attribute.setNotNull( false );
961 populate( _attribute, request );
962
963 if ( !validateBean( _attribute, getLocale( request ) ) )
964 {
965 return redirect( request, VIEW_MODIFY_ATTRIBUTE, PARAM_BUSINESS_CLASS_ID, nBusinessClassId, PARAM_ATTRIBUTE_ID, _attribute.getId( ) );
966 }
967
968 ModelService.updateAttribute( _nPluginId, nBusinessClassId, _attribute );
969 _attribute = null;
970 addInfo( INFO_ATTRIBUTE_UPDATED, getLocale( request ) );
971
972 return redirect( request, VIEW_MODIFY_BUSINESS_CLASS, PARAM_BUSINESS_CLASS_ID, nBusinessClassId, PARAM_REFRESH, 1 );
973 }
974
975
976
977
978
979
980
981
982 @Action( ACTION_CONFIRM_REMOVE_ATTRIBUTE )
983 public XPage getConfirmRemoveAttribute( HttpServletRequest request )
984 {
985 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
986 url.addParameter( PARAM_PAGE, PLUGIN_NAME );
987 url.addParameter( PARAM_ACTION, ACTION_REMOVE_ATTRIBUTE );
988 url.addParameter( PARAM_ATTRIBUTE_ID, request.getParameter( PARAM_ATTRIBUTE_ID ) );
989 url.addParameter( PARAM_BUSINESS_CLASS_ID, request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
990
991 return redirectMessageBox( request,
992 buildConfirmMessageBox( PROPERTY_CONFIRM_REMOVE_ATTRIBUTE_MESSAGE, url.getUrl( ), getViewFullUrl( VIEW_MODIFY_BUSINESS_CLASS ) ) );
993 }
994
995
996
997
998
999
1000
1001
1002 @Action( ACTION_REMOVE_ATTRIBUTE )
1003 public XPage doRemoveAttribute( HttpServletRequest request )
1004 {
1005 int nBusinessClassId = Integer.parseInt( request.getParameter( PARAM_BUSINESS_CLASS_ID ) );
1006 int nAttributeId = Integer.parseInt( request.getParameter( PARAM_ATTRIBUTE_ID ) );
1007 ModelService.removeAttribute( _nPluginId, nBusinessClassId, nAttributeId );
1008 addInfo( INFO_ATTRIBUTE_DELETED, getLocale( request ) );
1009
1010 return redirect( request, VIEW_MODIFY_BUSINESS_CLASS, PARAM_BUSINESS_CLASS_ID, nBusinessClassId, PARAM_REFRESH, 1 );
1011 }
1012
1013 @Action( ACTION_VALIDATE_ATTRIBUTES )
1014 public XPage doValidateAttributes( HttpServletRequest request )
1015 {
1016 return redirectView( request, VIEW_MANAGE_BUSINESS_CLASSES );
1017 }
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029 @View( VIEW_MANAGE_APPLICATIONS )
1030 public XPage getManageApplications( HttpServletRequest request )
1031 {
1032 Map<String, Object> model = getModel( );
1033 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
1034 model.put( MARK_PLUGIN_APPLICATIONS, ModelService.getPluginModel( _nPluginId ).getApplications( ) );
1035
1036 return getXPage( TEMPLATE_MANAGE_PLUGIN_APPLICATIONS, getLocale( request ), model );
1037 }
1038
1039
1040
1041
1042
1043
1044
1045
1046 @View( VIEW_CREATE_APPLICATION )
1047 public XPage getCreateApplication( HttpServletRequest request )
1048 {
1049 PluginModel pm = ModelService.getPluginModel( _nPluginId );
1050 _application = ( _application != null ) ? _application : new Application( );
1051
1052 Map<String, Object> model = getPluginModel( );
1053 model.put( MARK_APPLICATION, _application );
1054 model.put( MARK_PLUGIN_APPLICATIONS, pm.getApplications( ) );
1055 model.put( MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses( _nPluginId ) );
1056
1057 return getXPage( TEMPLATE_CREATE_PLUGIN_APPLICATION, getLocale( request ), model );
1058 }
1059
1060
1061
1062
1063
1064
1065
1066
1067 @View( VIEW_MODIFY_APPLICATION )
1068 public XPage getModifyApplication( HttpServletRequest request )
1069 {
1070 PluginModel pm = ModelService.getPluginModel( _nPluginId );
1071 int nApplicationId = Integer.parseInt( request.getParameter( PARAM_APPLICATION_ID ) );
1072
1073 if ( ( _application == null ) || ( _application.getId( ) != nApplicationId ) )
1074 {
1075 _application = ModelService.getApplication( _nPluginId, nApplicationId );
1076 }
1077
1078 Map<String, Object> model = getPluginModel( );
1079 model.put( MARK_APPLICATION, _application );
1080 model.put( MARK_PLUGIN_APPLICATIONS, pm.getApplications( ) );
1081 model.put( MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses( _nPluginId ) );
1082 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
1083
1084 return getXPage( TEMPLATE_MODIFY_PLUGIN_APPLICATION, getLocale( request ), model );
1085 }
1086
1087
1088
1089
1090
1091
1092
1093
1094 @Action( ACTION_CREATE_APPLICATION )
1095 public XPage doCreateApplication( HttpServletRequest request )
1096 {
1097 populate( _application, request );
1098
1099 List<Integer> listBusinessClasses = getBusinessClasses( request );
1100 _application.setIdBusinessClasses( listBusinessClasses );
1101
1102 if ( !validateBean( _application, getLocale( request ) ) )
1103 {
1104 return redirectView( request, VIEW_CREATE_APPLICATION );
1105 }
1106
1107 ModelService.addApplication( _nPluginId, _application );
1108 _application = null;
1109 addInfo( INFO_APPLICATION_CREATED, getLocale( request ) );
1110
1111 return redirectView( request, VIEW_MANAGE_APPLICATIONS );
1112 }
1113
1114
1115
1116
1117
1118
1119
1120
1121 @Action( ACTION_MODIFY_APPLICATION )
1122 public XPage doModifyApplication( HttpServletRequest request )
1123 {
1124 populate( _application, request );
1125
1126 List<Integer> listBusinessClasses = getBusinessClasses( request );
1127 _application.setIdBusinessClasses( listBusinessClasses );
1128
1129 if ( !validateBean( _application, getLocale( request ) ) )
1130 {
1131 return redirect( request, VIEW_MODIFY_APPLICATION, PARAM_APPLICATION_ID, _application.getId( ) );
1132 }
1133
1134 ModelService.updateApplication( _nPluginId, _application );
1135 _application = null;
1136 addInfo( INFO_APPLICATION_UPDATED, getLocale( request ) );
1137
1138 return redirectView( request, VIEW_MANAGE_APPLICATIONS );
1139 }
1140
1141
1142
1143
1144
1145
1146
1147
1148 @Action( ACTION_CONFIRM_REMOVE_APPLICATION )
1149 public XPage doConfirmRemoveApplication( HttpServletRequest request )
1150 {
1151 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
1152 url.addParameter( PARAM_PAGE, PLUGIN_NAME );
1153 url.addParameter( PARAM_ACTION, ACTION_REMOVE_APPLICATION );
1154 url.addParameter( PARAM_APPLICATION_ID, request.getParameter( PARAM_APPLICATION_ID ) );
1155
1156 return redirectMessageBox( request,
1157 buildConfirmMessageBox( PROPERTY_CONFIRM_REMOVE_APPLICATION_MESSAGE, url.getUrl( ), getViewFullUrl( VIEW_MANAGE_APPLICATIONS ) ) );
1158 }
1159
1160
1161
1162
1163
1164
1165
1166
1167 @Action( ACTION_REMOVE_APPLICATION )
1168 public XPage doRemoveApplication( HttpServletRequest request )
1169 {
1170 int nApplicationId = Integer.parseInt( request.getParameter( PARAM_APPLICATION_ID ) );
1171 ModelService.removeApplication( _nPluginId, nApplicationId );
1172 addInfo( INFO_APPLICATION_DELETED, getLocale( request ) );
1173
1174 return redirectView( request, VIEW_MANAGE_APPLICATIONS );
1175 }
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187 @View( VIEW_MANAGE_PORTLETS )
1188 public XPage getManagePortlets( HttpServletRequest request )
1189 {
1190 Map<String, Object> model = getModel( );
1191 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
1192 model.put( MARK_PLUGIN_PORTLETS, ModelService.getPluginModel( _nPluginId ).getPortlets( ) );
1193
1194 return getXPage( TEMPLATE_MANAGE_PLUGIN_PORTLETS, getLocale( request ), model );
1195 }
1196
1197
1198
1199
1200
1201
1202
1203
1204 @View( VIEW_CREATE_PORTLET )
1205 public XPage getCreatePortlet( HttpServletRequest request )
1206 {
1207 _portlet = ( _portlet != null ) ? _portlet : new Portlet( );
1208
1209 Map<String, Object> model = getPluginModel( );
1210 model.put( MARK_PORTLET, _portlet );
1211
1212 return getXPage( TEMPLATE_CREATE_PLUGIN_PORTLET, getLocale( request ), model );
1213 }
1214
1215
1216
1217
1218
1219
1220
1221
1222 @View( VIEW_MODIFY_PORTLET )
1223 public XPage getModifyPortlet( HttpServletRequest request )
1224 {
1225 int nPortletId = Integer.parseInt( request.getParameter( PARAM_PORTLET_ID ) );
1226
1227 if ( ( _portlet == null ) || ( _portlet.getId( ) != nPortletId ) )
1228 {
1229 _portlet = ModelService.getPortlet( _nPluginId, nPortletId );
1230 }
1231
1232 Map<String, Object> model = getModel( );
1233 model.put( MARK_PORTLET, _portlet );
1234
1235 return getXPage( TEMPLATE_MODIFY_PLUGIN_PORTLET, getLocale( request ), model );
1236 }
1237
1238
1239
1240
1241
1242
1243
1244
1245 @Action( ACTION_CREATE_PORTLET )
1246 public XPage doCreatePortlet( HttpServletRequest request )
1247 {
1248 populate( _portlet, request );
1249
1250 if ( !validateBean( _portlet, getLocale( request ) ) )
1251 {
1252 return redirectView( request, VIEW_CREATE_PORTLET );
1253 }
1254
1255 ModelService.addPortlet( _nPluginId, _portlet );
1256 _portlet = null;
1257 addInfo( INFO_PORTLET_CREATED, getLocale( request ) );
1258
1259 return redirectView( request, VIEW_MANAGE_PORTLETS );
1260 }
1261
1262
1263
1264
1265
1266
1267
1268
1269 @Action( ACTION_MODIFY_PORTLET )
1270 public XPage doModifyPluginPortlet( HttpServletRequest request )
1271 {
1272 populate( _portlet, request );
1273
1274 if ( !validateBean( _portlet, getLocale( request ) ) )
1275 {
1276 return redirect( request, ACTION_MODIFY_PORTLET, PARAM_PORTLET_ID, _portlet.getId( ) );
1277 }
1278
1279 ModelService.updatePortlet( _nPluginId, _portlet );
1280 _portlet = null;
1281 addInfo( INFO_PORTLET_UPDATED, getLocale( request ) );
1282
1283 return redirectView( request, VIEW_MANAGE_PORTLETS );
1284 }
1285
1286
1287
1288
1289
1290
1291
1292
1293 @Action( ACTION_CONFIRM_REMOVE_PORTLET )
1294 public XPage doConfirmRemovePortlet( HttpServletRequest request )
1295 {
1296 UrlItem url = new UrlItem( JSP_PAGE_PORTAL );
1297 url.addParameter( PARAM_PAGE, PLUGIN_NAME );
1298 url.addParameter( PARAM_ACTION, ACTION_REMOVE_PORTLET );
1299 url.addParameter( PARAM_PORTLET_ID, request.getParameter( PARAM_PORTLET_ID ) );
1300
1301 return redirectMessageBox( request,
1302 buildConfirmMessageBox( PROPERTY_CONFIRM_REMOVE_PORTLET_MESSAGE, url.getUrl( ), getViewFullUrl( VIEW_MANAGE_PORTLETS ) ) );
1303 }
1304
1305
1306
1307
1308
1309
1310
1311
1312 @Action( ACTION_REMOVE_PORTLET )
1313 public XPage doRemovePluginPortlet( HttpServletRequest request )
1314 {
1315 int nPluginPortletId = Integer.parseInt( request.getParameter( PARAM_PORTLET_ID ) );
1316 ModelService.removePortlet( _nPluginId, nPluginPortletId );
1317 addInfo( INFO_PORTLET_DELETED, getLocale( request ) );
1318
1319 return redirectView( request, VIEW_MANAGE_PORTLETS );
1320 }
1321
1322
1323
1324
1325
1326
1327
1328
1329 @View( VIEW_RECAPITULATE )
1330 public XPage getPluginRecapitulate( HttpServletRequest request )
1331 {
1332 PluginModel pm = ModelService.getPluginModel( _nPluginId );
1333
1334 Map<String, Object> model = getPluginModel( );
1335 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
1336 model.put( MARK_PLUGIN_APPLICATIONS, pm.getApplications( ) );
1337 model.put( MARK_ADMIN_FEATURES, pm.getFeatures( ) );
1338 model.put( MARK_PLUGIN_PORTLETS, pm.getPortlets( ) );
1339 model.put( MARK_PLUGIN_REST, pm.getRest( ) );
1340 model.put( MARK_BUSINESS_CLASSES, pm.getBusinessClasses( ) );
1341 model.put( MARK_SCHEMES_COMBO, GeneratorService.getGenerationSchemes( ) );
1342
1343 return getXPage( TEMPLATE_GET_RECAPITULATE, getLocale( request ), model );
1344 }
1345
1346
1347
1348
1349
1350
1351 private Map<String, Object> getPluginModel( )
1352 {
1353 Map<String, Object> model = getModel( );
1354 model.put( MARK_PLUGIN_MODEL, ModelService.getPluginModel( _nPluginId ) );
1355
1356 return model;
1357 }
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372 private MVCMessageBox buildConfirmMessageBox( String strMessageKey, String strUrlConfirm, String strUrlBack )
1373 {
1374 MVCMessageBox box = new MVCMessageBox( );
1375 box.setTemplate( TEMPLATE_MESSAGE_BOX_CONFIRMATION );
1376 box.setMessageKey( strMessageKey );
1377 box.setStyle( MVCMessageBox.QUESTION );
1378 box.setUrlButton1( strUrlConfirm );
1379 box.setUrlButton2( strUrlBack );
1380
1381 return box;
1382 }
1383
1384
1385
1386
1387
1388
1389 private MVCMessageBox buildExistsMessageBox( )
1390 {
1391 MVCMessageBox box = new MVCMessageBox( );
1392 box.setTemplate( TEMPLATE_MESSAGE_BOX_EXISTS );
1393 box.setMessage( _strPluginName );
1394
1395 return box;
1396 }
1397
1398
1399
1400
1401
1402
1403
1404
1405 private List<Integer> getBusinessClasses( HttpServletRequest request )
1406 {
1407 List<Integer> list = new ArrayList<>( );
1408 Enumeration e = request.getParameterNames( );
1409
1410 while ( e.hasMoreElements( ) )
1411 {
1412 String strParameter = (String) e.nextElement( );
1413
1414 if ( strParameter.startsWith( PARAM_ID_BUSINESS_CLASS ) )
1415 {
1416 String strId = strParameter.substring( PARAM_ID_BUSINESS_CLASS.length( ) );
1417 list.add( Integer.parseInt( strId ) );
1418 }
1419 }
1420
1421 return list;
1422 }
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434 @View( VIEW_MANAGE_REST )
1435 public XPage getManageRest( HttpServletRequest request )
1436 {
1437 Map<String, Object> model = getModel( );
1438
1439 if ( ModelService.getRest( _nPluginId ) == null )
1440 {
1441 _rest = new Rest( );
1442 _rest.setIdBusinessClasses( new ArrayList<Integer>( ) );
1443 _rest.setId( 1 );
1444 ModelService.addRest( _nPluginId, _rest );
1445 }
1446 else
1447 {
1448 _rest = ModelService.getRest( _nPluginId );
1449 }
1450
1451 model.put( MARK_PLUGIN_ID, Integer.toString( _nPluginId ) );
1452 model.put( MARK_BUSINESS_CLASSES_COMBO, ModelService.getComboBusinessClasses( _nPluginId ) );
1453 model.put( MARK_PLUGIN_REST, ModelService.getRest( _nPluginId ) );
1454
1455 return getXPage( TEMPLATE_MANAGE_REST, getLocale( request ), model );
1456 }
1457
1458
1459
1460
1461
1462
1463
1464
1465 @Action( ACTION_MODIFY_REST_BACK )
1466 public XPage doModifyRestBack( HttpServletRequest request )
1467 {
1468 populate( _rest, request );
1469
1470 List<Integer> listBusinessClasses = getBusinessClasses( request );
1471 _rest.setIdBusinessClasses( listBusinessClasses );
1472
1473 if ( !validateBean( _rest, getLocale( request ) ) )
1474 {
1475 return redirect( request, VIEW_MANAGE_REST );
1476 }
1477
1478 ModelService.updateRest( _nPluginId, _rest );
1479
1480 return redirectView( request, VIEW_MANAGE_PORTLETS );
1481 }
1482
1483
1484
1485
1486
1487
1488
1489
1490 @Action( ACTION_MODIFY_REST_NEXT )
1491 public XPage doModifyRestNext( HttpServletRequest request )
1492 {
1493 populate( _rest, request );
1494
1495 List<Integer> listBusinessClasses = getBusinessClasses( request );
1496 _rest.setIdBusinessClasses( listBusinessClasses );
1497
1498 if ( !validateBean( _rest, getLocale( request ) ) )
1499 {
1500 return redirect( request, VIEW_MANAGE_REST );
1501 }
1502
1503 ModelService.updateRest( _nPluginId, _rest );
1504
1505 return redirectView( request, VIEW_RECAPITULATE );
1506 }
1507 }