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.forms.service;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Locale;
39
40 import fr.paris.lutece.plugins.forms.business.form.panel.configuration.IFormPanelConfiguration;
41 import fr.paris.lutece.portal.service.i18n.I18nService;
42 import fr.paris.lutece.portal.service.rbac.Permission;
43 import fr.paris.lutece.portal.service.rbac.ResourceIdService;
44 import fr.paris.lutece.portal.service.rbac.ResourceType;
45 import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
46 import fr.paris.lutece.portal.service.spring.SpringContextService;
47 import fr.paris.lutece.util.ReferenceList;
48
49 public class FormPanelConfigIdService extends ResourceIdService
50 {
51
52
53
54
55 public static final String PERMISSION_VIEW = "VIEW";
56
57 private static final String PROPERTY_LABEL_RESOURCE_TYPE = "forms.permission.panel.label.resourceType";
58
59 private static final String PROPERTY_LABEL_VIEW = "forms.permission.panel.label.view";
60
61 private List<IFormPanelConfiguration> _listFormPanelConfiguration;
62
63 @Override
64 public ReferenceList getResourceIdList( Locale locale )
65 {
66 ReferenceList list = new ReferenceList( );
67 List<IFormPanelConfiguration> listFormPanelConfiguration = getListFormPanelConfiguration( );
68 for ( IFormPanelConfiguration panelConfiguration : listFormPanelConfiguration )
69 {
70 list.addItem( panelConfiguration.getResourceId( ), I18nService.getLocalizedString( panelConfiguration.getTitle( ), locale ) );
71 }
72 return list;
73 }
74
75 @Override
76 public void register( )
77 {
78 ResourceType resourceType = new ResourceType( );
79 resourceType.setResourceIdServiceClass( FormPanelConfigIdService.class.getName( ) );
80 resourceType.setPluginName( FormsPlugin.PLUGIN_NAME );
81 resourceType.setResourceTypeKey( IFormPanelConfiguration.RESOURCE_TYPE );
82 resourceType.setResourceTypeLabelKey( PROPERTY_LABEL_RESOURCE_TYPE );
83
84 Permission permission = new Permission( );
85 permission.setPermissionKey( PERMISSION_VIEW );
86 permission.setPermissionTitleKey( PROPERTY_LABEL_VIEW );
87 resourceType.registerPermission( permission );
88
89 ResourceTypeManager.registerResourceType( resourceType );
90 }
91
92 private List<IFormPanelConfiguration> getListFormPanelConfiguration( )
93 {
94 if ( _listFormPanelConfiguration == null )
95 {
96 _listFormPanelConfiguration = SpringContextService.getBeansOfType( IFormPanelConfiguration.class );
97 }
98 return new ArrayList<>( _listFormPanelConfiguration );
99 }
100
101 @Override
102 public String getTitle( String strId, Locale locale )
103 {
104 String title = "";
105 List<IFormPanelConfiguration> listFormPanelConfiguration = getListFormPanelConfiguration( );
106 for ( IFormPanelConfiguration panelConfiguration : listFormPanelConfiguration )
107 {
108 if ( panelConfiguration.getResourceId( ).equals( strId ) )
109 {
110 title = I18nService.getLocalizedString( panelConfiguration.getTitle( ), locale );
111 break;
112 }
113 }
114 return title;
115 }
116 }