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.participatoryideation.service;
35
36 import java.util.ArrayList;
37 import java.util.Arrays;
38 import java.util.Collection;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Locale;
42 import java.util.Map;
43
44 import fr.paris.lutece.plugins.participatoryideation.business.proposal.Proposal;
45 import fr.paris.lutece.plugins.participatoryideation.business.submitter.SubmitterType;
46 import fr.paris.lutece.plugins.participatoryideation.business.submitter.SubmitterTypeHome;
47 import fr.paris.lutece.plugins.participatoryideation.service.campaign.IdeationCampaignDataProvider;
48 import fr.paris.lutece.portal.service.cache.AbstractCacheableService;
49 import fr.paris.lutece.portal.service.i18n.I18nService;
50 import fr.paris.lutece.portal.service.spring.SpringContextService;
51 import fr.paris.lutece.portal.service.util.AppLogService;
52 import fr.paris.lutece.portal.service.workflow.WorkflowService;
53 import fr.paris.lutece.util.ReferenceItem;
54 import fr.paris.lutece.util.ReferenceList;
55
56 public class IdeationStaticService extends AbstractCacheableService implements IIdeationStaticService
57 {
58
59 private static IIdeationStaticService _singleton;
60 private static final String BEAN_IDEATION_STATIC_SERVICE = "participatoryideation.ideationStaticService";
61
62 private static final String SERVICE_NAME = "Ideation Static Cache";
63
64 private static final String MARK_GLOBAL_STATIC = "global_static";
65 private static final String MARK_CAMPAIGN_STATIC = "campaign_static";
66 private static final String MARK_LIST_CAMPAIGN = "list_campaign";
67 private static final String MARK_LIST_STATUS_STATIC = "status_static_list";
68
69 private static final String MARK_CAMPAIGN = "campaign";
70
71 private static final String MARK_AREA_LIST = "area_list";
72
73 private static final String MARK_THEME_LABEL_LIST = "theme_label_list";
74 private static final String MARK_THEME_FRONT_RGB_LIST = "theme_front_rgb_list";
75
76 private static final String MARK_QPVQVA_LIST = "qpvqva_list";
77 private static final String MARK_QPVQVA_MAP = "qpvqva_map";
78
79 private static final String MARK_LOCATION_TYPE_LIST = "type_location_list";
80 private static final String MARK_LOCATION_TYPE_MAP = "type_location_map";
81
82 private static final String MARK_FIELD4_CODES_LIST = "field4_list";
83 private static final String MARK_FIELD4_CODES_MAP = "field4_map";
84
85 private static final String MARK_SUBMITTERS_TYPES_LIST = "submitter_types_list";
86 private static final String MARK_SUBMITTERS_TYPES_MAP = "submitters_types_map";
87 private static final String MARK_SUBMITTERS_TYPES_LIST_VALUES_MAP = "submitters_types_list_values_map";
88
89 private static final String MARK_FIELD_MAP = "type_field_map";
90
91 public static final String CACHE_KEY = "[ideationStatic]";
92
93
94
95
96
97
98 public static IIdeationStaticService getInstance( )
99 {
100 if ( _singleton == null )
101 {
102 _singleton = SpringContextService.getBean( BEAN_IDEATION_STATIC_SERVICE );
103 }
104 return _singleton;
105 }
106
107 public IdeationStaticService( )
108 {
109 initCache( );
110 }
111
112 public String getName( )
113 {
114 return SERVICE_NAME;
115 }
116
117
118
119
120
121
122
123
124
125 public void fillCampaignStaticContent( Map<String, Object> model, String strCampaignCode )
126 {
127
128 model.put( MARK_QPVQVA_LIST, ProposalService.getInstance( ).getQpvQvaCodesList( ) );
129 model.put( MARK_QPVQVA_MAP, ProposalService.getInstance( ).getQpvQvaCodesMap( ) );
130
131 model.put( MARK_LOCATION_TYPE_LIST, ProposalService.getInstance( ).getTypeLocationList( ) );
132 model.put( MARK_LOCATION_TYPE_MAP, ProposalService.getInstance( ).getTypeLocationMap( ) );
133
134 model.put( MARK_FIELD4_CODES_LIST, ProposalService.getInstance( ).getField4CodesList( ) );
135 model.put( MARK_FIELD4_CODES_MAP, ProposalService.getInstance( ).getField4CodesMap( ) );
136
137
138 model.put( MARK_LIST_CAMPAIGN, IdeationCampaignDataProvider.getInstance( ).getCampaigns( ) );
139
140
141 if ( WorkflowService.getInstance( ).isAvailable( ) )
142 {
143 List<Proposal.Status> enumList = Arrays.asList( Proposal.Status.values( ) );
144 ReferenceList WorkflowStatesReferenceList = new ReferenceList( );
145 for ( Proposal.Status status : enumList )
146 {
147 if ( status.isPublished( ) )
148 {
149 WorkflowStatesReferenceList.addItem( status.getValeur( ),
150 I18nService.getLocalizedString( status.getLibelle( ), new Locale( "fr", "FR" ) ) );
151 }
152 }
153 model.put( MARK_LIST_STATUS_STATIC, WorkflowStatesReferenceList );
154 }
155
156
157 @SuppressWarnings( "unchecked" )
158 Map<String, Object> cached = (Map<String, Object>) getFromCache( CACHE_KEY );
159 if ( cached == null )
160 {
161 cached = putAllStaticContentInCache( );
162 }
163 model.put( MARK_CAMPAIGN_STATIC, cached.get( strCampaignCode ) );
164 }
165
166
167
168
169
170
171
172
173
174 public void fillAllStaticContent( Map<String, Object> model )
175 {
176
177 model.put( MARK_QPVQVA_LIST, ProposalService.getInstance( ).getQpvQvaCodesList( ) );
178 model.put( MARK_QPVQVA_MAP, ProposalService.getInstance( ).getQpvQvaCodesMap( ) );
179
180 model.put( MARK_LOCATION_TYPE_LIST, ProposalService.getInstance( ).getTypeLocationList( ) );
181 model.put( MARK_LOCATION_TYPE_MAP, ProposalService.getInstance( ).getTypeLocationMap( ) );
182
183 model.put( MARK_FIELD4_CODES_LIST, ProposalService.getInstance( ).getField4CodesList( ) );
184 model.put( MARK_FIELD4_CODES_MAP, ProposalService.getInstance( ).getField4CodesMap( ) );
185
186
187 @SuppressWarnings( "unchecked" )
188 Map<String, Object> cached = (Map<String, Object>) getFromCache( CACHE_KEY );
189 if ( cached == null )
190 {
191 cached = putAllStaticContentInCache( );
192 }
193 model.put( MARK_GLOBAL_STATIC, cached );
194
195 }
196
197
198
199
200
201
202
203
204
205 private Map<String, Object> putAllStaticContentInCache( )
206 {
207 Map<String, Object> content = new HashMap<String, Object>( );
208
209
210 Map<String, List<SubmitterType>> mapSubmittersTypes = SubmitterTypeHome.getSubmitterTypesMapByCampaign( );
211 ReferenceList listCampaign = IdeationCampaignDataProvider.getInstance( ).getCampaigns( );
212 for ( ReferenceItem campaign : listCampaign )
213 {
214 Map<String, Object> campaignContent = new HashMap<String, Object>( );
215
216
217 campaignContent.put( MARK_CAMPAIGN, campaign );
218
219
220 campaignContent.put( MARK_THEME_LABEL_LIST, IdeationCampaignDataProvider.getInstance( ).getCampaignThemes( campaign.getCode( ) ) );
221 campaignContent.put( MARK_THEME_FRONT_RGB_LIST, IdeationCampaignDataProvider.getInstance( ).getCampaignThemesFrontRgb( campaign.getCode( ) ) );
222
223
224 campaignContent.put( MARK_AREA_LIST, IdeationCampaignDataProvider.getInstance( ).getCampaignAllAreaLabels( campaign.getCode( ) ) );
225
226
227 Collection<SubmitterType> submitterTypes = mapSubmittersTypes.get( campaign.getCode( ) );
228 if ( submitterTypes == null )
229 {
230 AppLogService.error( "No submitter type found for campaign '" + campaign.getCode( ) + "'." );
231 submitterTypes = new ArrayList<>( );
232 }
233
234 campaignContent.put( MARK_SUBMITTERS_TYPES_LIST, submitterTypes );
235 Map<String, SubmitterType> mapSubmittersTypesByCode = new HashMap<String, SubmitterType>( );
236 for ( SubmitterType submitterType : submitterTypes )
237 {
238 mapSubmittersTypesByCode.put( submitterType.getCode( ), submitterType );
239 }
240 campaignContent.put( MARK_SUBMITTERS_TYPES_MAP, mapSubmittersTypesByCode );
241
242
243 Map<String, String> mapSubmittersTypesListValuesByCode = new HashMap<String, String>( );
244 for ( SubmitterType submitterType : submitterTypes )
245 {
246 if ( SubmitterType.CODE_COMPLEMENT_TYPE_LIST.equals( submitterType.getCodeComplementType( ) ) )
247 {
248 for ( ReferenceItem referenceItem : submitterType.getValues( ) )
249 {
250 mapSubmittersTypesListValuesByCode.put( submitterType.getCode( ) + "-" + referenceItem.getCode( ), referenceItem.getName( ) );
251 }
252 }
253 }
254 campaignContent.put( MARK_SUBMITTERS_TYPES_LIST_VALUES_MAP, mapSubmittersTypesListValuesByCode );
255
256
257 campaignContent.put( MARK_FIELD_MAP, IdeationCampaignDataProvider.getInstance( ).getCampaignFieldsData( campaign.getCode( ) ) );
258
259 content.put( campaign.getCode( ), campaignContent );
260 }
261
262 putInCache( CACHE_KEY, content );
263
264 return content;
265 }
266
267 }