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.portal.service.resource;
35
36 import fr.paris.lutece.portal.service.spring.SpringContextService;
37
38 import java.util.HashMap;
39 import java.util.Map;
40 import java.util.Map.Entry;
41
42
43
44
45
46
47 public final class ExtendableResourceActionHit
48 {
49
50
51
52 public static final String ACTION_DOWNLOAD = "download";
53
54
55
56
57 public static final String ACTION_CREATION = "creation";
58
59
60
61
62 public static final String ACTION_UPDATE = "update";
63
64
65
66
67 public static final String ACTION_ARCHIVE = "archive";
68
69
70
71
72 public static final String ACTION_DELETE = "delete";
73 private static volatile ExtendableResourceActionHit _instance;
74
75
76
77
78 private ExtendableResourceActionHit( )
79 {
80 }
81
82
83
84
85
86 public static ExtendableResourceActionHit getInstance( )
87 {
88 if ( _instance == null )
89 {
90 synchronized ( ExtendableResourceActionHit.class )
91 {
92 _instance = new ExtendableResourceActionHit( );
93 }
94 }
95
96 return _instance;
97 }
98
99
100
101
102
103
104
105
106
107 public int getActionHit( String strActionName, String strExtendableResourceType )
108 {
109 int nResult = 0;
110
111 for ( IExtendableResourceActionHitListener listener : SpringContextService.getBeansOfType(
112 IExtendableResourceActionHitListener.class ) )
113 {
114 nResult += listener.getActionHit( strActionName, strExtendableResourceType );
115 }
116
117 return nResult;
118 }
119
120
121
122
123
124
125
126
127 public Map<String, Integer> getResourceHit( String strExtendableResourceId, String strExtendableResourceType )
128 {
129 Map<String, Integer> mapActionHit = new HashMap<String, Integer>( );
130
131 for ( IExtendableResourceActionHitListener listener : SpringContextService.getBeansOfType(
132 IExtendableResourceActionHitListener.class ) )
133 {
134 for ( Entry<String, Integer> entry : listener.getResourceHit( strExtendableResourceId,
135 strExtendableResourceType ).entrySet( ) )
136 {
137 if ( mapActionHit.containsKey( entry.getKey( ) ) )
138 {
139 mapActionHit.put( entry.getKey( ), mapActionHit.get( entry.getKey( ) ) + entry.getValue( ) );
140 }
141 else
142 {
143 mapActionHit.put( entry.getKey( ), entry.getValue( ) );
144 }
145 }
146 }
147
148 return mapActionHit;
149 }
150
151
152
153
154
155
156
157
158
159 public int getResourceActionHit( String strExtendableResourceId, String strExtendableResourceType,
160 String strActionName )
161 {
162 int nResult = 0;
163
164 for ( IExtendableResourceActionHitListener listener : SpringContextService.getBeansOfType(
165 IExtendableResourceActionHitListener.class ) )
166 {
167 nResult += listener.getResourceActionHit( strExtendableResourceId, strExtendableResourceType, strActionName );
168 }
169
170 return nResult;
171 }
172
173
174
175
176
177
178
179
180
181
182
183
184 public void notifyActionOnResource( String strExtendableResourceId, String strExtendableResourceType,
185 String strActionName )
186 {
187 for ( IExtendableResourceActionHitListener listener : SpringContextService.getBeansOfType(
188 IExtendableResourceActionHitListener.class ) )
189 {
190 listener.notifyActionOnResource( strExtendableResourceId, strExtendableResourceType, strActionName );
191 }
192 }
193 }