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.service;
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.portal.service.plugin.Plugin;
39 import fr.paris.lutece.portal.service.plugin.PluginService;
40 import fr.paris.lutece.portal.service.rbac.Permission;
41 import fr.paris.lutece.portal.service.rbac.ResourceIdService;
42 import fr.paris.lutece.portal.service.rbac.ResourceType;
43 import fr.paris.lutece.portal.service.rbac.ResourceTypeManager;
44 import fr.paris.lutece.util.ReferenceList;
45
46 import org.apache.commons.lang.StringUtils;
47
48 import java.util.Locale;
49
50
51
52
53
54
55 public class MyAppsDatabaseResourceIdService extends ResourceIdService
56 {
57 public static final String PERMISSION_CREATE_MYAPPS_DATABASE = "CREATE_MYAPPS_DATABASE";
58 public static final String PERMISSION_MODIFY_MYAPPS_DATABASE = "MODIFY_MYAPPS_DATABASE";
59 public static final String PERMISSION_DELETE_MYAPPS_DATABASE = "DELETE_MYAPPS_DATABASE";
60 private static final String PROPERTY_LABEL_RESOURCE_TYPE = "module.myapps.database.permission.ressourceType";
61 private static final String PROPERTY_LABEL_CREATE = "module.myapps.database.permission.createMyAppsDatabase";
62 private static final String PROPERTY_LABEL_MODIFY = "module.myapps.database.permission.modifyMyAppsDatabase";
63 private static final String PROPERTY_LABEL_DELETE = "module.myapps.database.permission.deleteMyAppsDatabase";
64
65
66
67
68 public MyAppsDatabaseResourceIdService( )
69 {
70 setPluginName( MyAppsDatabasePlugin.PLUGIN_NAME );
71 }
72
73
74
75
76 public void register( )
77 {
78 ResourceType rt = new ResourceType( );
79 rt.setResourceIdServiceClass( MyAppsDatabaseResourceIdService.class.getName( ) );
80 rt.setPluginName( MyAppsDatabasePlugin.PLUGIN_NAME );
81 rt.setResourceTypeKey( MyAppsDatabase.RESOURCE_TYPE );
82 rt.setResourceTypeLabelKey( PROPERTY_LABEL_RESOURCE_TYPE );
83
84 Permission p = new Permission( );
85 p.setPermissionKey( PERMISSION_CREATE_MYAPPS_DATABASE );
86 p.setPermissionTitleKey( PROPERTY_LABEL_CREATE );
87 rt.registerPermission( p );
88
89 p = new Permission( );
90 p.setPermissionKey( PERMISSION_MODIFY_MYAPPS_DATABASE );
91 p.setPermissionTitleKey( PROPERTY_LABEL_MODIFY );
92 rt.registerPermission( p );
93
94 p = new Permission( );
95 p.setPermissionKey( PERMISSION_DELETE_MYAPPS_DATABASE );
96 p.setPermissionTitleKey( PROPERTY_LABEL_DELETE );
97 rt.registerPermission( p );
98
99 ResourceTypeManager.registerResourceType( rt );
100 }
101
102
103
104
105
106
107
108
109 public ReferenceList getResourceIdList( Locale locale )
110 {
111 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
112
113 return MyAppsDatabaseService.getInstance( ).getMyApps( plugin );
114 }
115
116
117
118
119
120
121
122
123
124
125 public String getTitle( String strMyAppId, Locale locale )
126 {
127 String strTitle = StringUtils.EMPTY;
128
129 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
130 {
131 int nMyAppsId = Integer.parseInt( strMyAppId );
132 Plugin plugin = PluginService.getPlugin( getPluginName( ) );
133 MyApps myApps = MyAppsDatabaseService.getInstance( ).findByPrimaryKey( nMyAppsId, plugin );
134
135 if ( myApps != null )
136 {
137 strTitle = myApps.getName( );
138 }
139 }
140
141 return strTitle;
142 }
143 }