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 getFormCacheKey( int nIdForm )
72 {
73 return new StringBuilder( "Form-id:" ).append( nIdForm ).toString( );
74 }
75
76 public String getFormListCacheKey( )
77 {
78 return "FormList";
79 }
80
81 public String getControlCacheKey( int nIdControl )
82 {
83 return new StringBuilder( "Control-id:" ).append( nIdControl ).toString( );
84 }
85
86 public String getControlByControlTargetAndTypeCacheKey( int nIdControlTarget, ControlType controlType )
87 {
88 return new StringBuilder( "Control-by-Target:" ).append( nIdControlTarget ).append( "-and-Type:" )
89 .append( controlType ).toString( );
90 }
91
92 public String getControlByQuestionAndTypeCacheKey( int nIdQuestion, String strControlType )
93 {
94 return new StringBuilder( "Control-by-Question:" ).append( nIdQuestion ).append( "-and-Type:" )
95 .append( strControlType ).toString( );
96 }
97
98 public String getQuestionCacheKey( int nIdQuestion )
99 {
100 return new StringBuilder( "Question-id:" ).append( nIdQuestion ).toString( );
101 }
102
103 public String getFormDisplayCacheKey( int nIdFormDisplay )
104 {
105 return new StringBuilder( "FormDisplay-id:" ).append( nIdFormDisplay ).toString( );
106 }
107
108 public String getFormDisplayListByParentCacheKey( int nIdStep, int nIdParent )
109 {
110 return new StringBuilder( "FormDisplayList-by-Step:" ).append( nIdStep ).append( "-and-Parent:" )
111 .append( nIdParent ).toString( );
112 }
113
114 public String getGroupCacheKey( int nIdGroup )
115 {
116 return new StringBuilder( "Group-id:" ).append( nIdGroup ).toString( );
117 }
118
119 public String getControlGroupCacheKey( int nIdControlGroup )
120 {
121 return new StringBuilder( "ControlGroup-id:" ).append( nIdControlGroup ).toString( );
122 }
123
124 public String getTransitionsListFromStepCacheKey( int nIdStep )
125 {
126 return new StringBuilder( "TransitionsList-From-Step:" ).append( nIdStep ).toString( );
127 }
128
129 public String getFormMessageByFormCacheKey( int nIdForm )
130 {
131 return new StringBuilder( "FormMessage-by-Form:" ).append( nIdForm ).toString( );
132 }
133
134 @Override
135 public void addedResource( ResourceEvent event )
136 {
137 handleEvent( event );
138 }
139
140 @Override
141 public void deletedResource( ResourceEvent event )
142 {
143 handleEvent( event );
144 }
145
146 @Override
147 public void updatedResource( ResourceEvent event )
148 {
149 handleEvent( event );
150 }
151
152 private void handleEvent( ResourceEvent event )
153 {
154 if ( Form.RESOURCE_TYPE.equals( event.getTypeResource( ) ) )
155 {
156
157
158
159 resetCache( );
160 }
161 }
162 }