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.cache;
35
36 import fr.paris.lutece.plugins.forms.business.ControlType;
37 import fr.paris.lutece.plugins.forms.business.Form;
38 import fr.paris.lutece.portal.business.event.EventRessourceListener;
39 import fr.paris.lutece.portal.business.event.ResourceEvent;
40 import fr.paris.lutece.portal.service.cache.AbstractCacheableService;
41 import fr.paris.lutece.portal.service.event.ResourceEventManager;
42
43 public class FormsCacheService extends AbstractCacheableService implements EventRessourceListener
44 {
45
46 private static final String CACHE_NAME = "formsCacheService";
47
48 @Override
49 public void initCache( )
50 {
51 super.initCache( );
52 ResourceEventManager.register( this );
53 }
54
55 @Override
56 public String getName( )
57 {
58 return CACHE_NAME;
59 }
60
61 public String getStepCacheKey( int nStepID )
62 {
63 return new StringBuilder( "Step-id:" ).append( nStepID ).toString( );
64 }
65
66 public String getInitialStepCacheKey( int nIdForm )
67 {
68 return new StringBuilder( "Initial-Step-For-Form-id:" ).append( nIdForm ).toString( );
69 }
70
71 public String getIdStepByFormKey( int nIdQuestion )
72 {
73 return new StringBuilder( "Step-For-Form-id:" ).append( nIdQuestion ).toString( );
74 }
75
76 public String getFormCacheKey( int nIdForm )
77 {
78 return new StringBuilder( "Form-id:" ).append( nIdForm ).toString( );
79 }
80
81 public String getFormListCacheKey( )
82 {
83 return "FormList";
84 }
85
86 public String getControlCacheKey( int nIdControl )
87 {
88 return new StringBuilder( "Control-id:" ).append( nIdControl ).toString( );
89 }
90
91 public String getControlByControlTargetAndTypeCacheKey( int nIdControlTarget, ControlType controlType )
92 {
93 return new StringBuilder( "Control-by-Target:" ).append( nIdControlTarget ).append( "-and-Type:" )
94 .append( controlType ).toString( );
95 }
96
97 public String getControlByQuestionAndTypeCacheKey( int nIdQuestion, String strControlType )
98 {
99 return new StringBuilder( "Control-by-Question:" ).append( nIdQuestion ).append( "-and-Type:" )
100 .append( strControlType ).toString( );
101 }
102
103 public String getQuestionCacheKey( int nIdQuestion )
104 {
105 return new StringBuilder( "Question-id:" ).append( nIdQuestion ).toString( );
106 }
107
108 public String getUncompleteQuestionCacheKey( )
109 {
110 return new StringBuilder( "Question-Uncomplete" ).toString( );
111 }
112
113 public String getUncompleteQuestionByFormCacheKey( int nIdForm )
114 {
115 return new StringBuilder( "Question-Uncomplete-by-Form:" ).append( nIdForm ).toString( );
116 }
117
118 public String getFormDisplayCacheKey( int nIdFormDisplay )
119 {
120 return new StringBuilder( "FormDisplay-id:" ).append( nIdFormDisplay ).toString( );
121 }
122
123 public String getFormDisplayListByParentCacheKey( int nIdStep, int nIdParent )
124 {
125 return new StringBuilder( "FormDisplayList-by-Step:" ).append( nIdStep ).append( "-and-Parent:" )
126 .append( nIdParent ).toString( );
127 }
128
129 public String getGroupCacheKey( int nIdGroup )
130 {
131 return new StringBuilder( "Group-id:" ).append( nIdGroup ).toString( );
132 }
133
134 public String getControlGroupCacheKey( int nIdControlGroup )
135 {
136 return new StringBuilder( "ControlGroup-id:" ).append( nIdControlGroup ).toString( );
137 }
138
139 public String getTransitionsListFromStepCacheKey( int nIdStep )
140 {
141 return new StringBuilder( "TransitionsList-From-Step:" ).append( nIdStep ).toString( );
142 }
143
144 public String getFormMessageByFormCacheKey( int nIdForm )
145 {
146 return new StringBuilder( "FormMessage-by-Form:" ).append( nIdForm ).toString( );
147 }
148
149 @Override
150 public void addedResource( ResourceEvent event )
151 {
152 handleEvent( event );
153 }
154
155 @Override
156 public void deletedResource( ResourceEvent event )
157 {
158 handleEvent( event );
159 }
160
161 @Override
162 public void updatedResource( ResourceEvent event )
163 {
164 handleEvent( event );
165 }
166
167 private void handleEvent( ResourceEvent event )
168 {
169 if ( Form.RESOURCE_TYPE.equals( event.getTypeResource( ) ) )
170 {
171
172
173
174 resetCache( );
175 }
176 }
177 }