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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 package fr.paris.lutece.plugins.participatorybudget.web.rs;
69
70 import javax.servlet.ServletException;
71 import javax.servlet.http.HttpServletRequest;
72 import javax.ws.rs.GET;
73 import javax.ws.rs.Path;
74 import javax.ws.rs.PathParam;
75 import javax.ws.rs.Produces;
76 import javax.ws.rs.core.Context;
77 import javax.ws.rs.core.MediaType;
78
79 import fr.paris.lutece.plugins.participatorybudget.business.campaign.CampaignHome;
80 import fr.paris.lutece.plugins.participatorybudget.service.NoSuchPhaseException;
81 import fr.paris.lutece.plugins.participatorybudget.service.campaign.CampaignService;
82 import fr.paris.lutece.plugins.rest.service.RestConstants;
83 import fr.paris.lutece.portal.service.util.AppLogService;
84
85 @Path( RestConstants.BASE_PATH + "campaign" )
86 public class CampaignRest extends AbstractServiceRest
87 {
88
89 private static final String LOG_UNAUTHENTICATED_REQUEST = "Calling Campaign rest API with unauthenticated request";
90
91
92
93
94
95
96
97
98
99
100
101
102 @GET
103 @Path( "campaigns" )
104 @Produces( MediaType.APPLICATION_JSON )
105 public String getCampaigns( @Context HttpServletRequest request ) throws ServletException
106 {
107 if ( !isRequestAuthenticated( request ) )
108 {
109 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
110 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
111 }
112 try
113 {
114 return formatJson( "OK", CampaignHome.getCampaignsList( ) );
115 }
116 catch( NoSuchPhaseException e )
117 {
118 AppLogService.error( e );
119 return formatJson( "KO", false );
120 }
121 }
122
123
124
125
126
127
128
129
130
131
132
133
134 @GET
135 @Path( "{campaign}/{phase}/before-beginning" )
136 @Produces( MediaType.APPLICATION_JSON )
137 public String isBeforeBeginning( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign, @PathParam( "phase" ) String phase )
138 throws ServletException
139 {
140 if ( !isRequestAuthenticated( request ) )
141 {
142 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
143 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
144 }
145 try
146 {
147 return formatJson( "OK", CampaignService.getInstance( ).isBeforeBeginning( campaign, phase ),
148 CampaignService.getInstance( ).start( campaign, phase ) + " ==> " + CampaignService.getInstance( ).end( campaign, phase ) );
149 }
150 catch( NoSuchPhaseException e )
151 {
152 AppLogService.error( e );
153 return formatJson( "KO", false );
154 }
155 }
156
157
158
159
160
161
162
163 @GET
164 @Path( "{phase}/before-beginning" )
165 @Produces( MediaType.APPLICATION_JSON )
166 public String isBeforeBeginningLastCampaign( @Context HttpServletRequest request, @PathParam( "phase" ) String phase ) throws ServletException
167 {
168 if ( !isRequestAuthenticated( request ) )
169 {
170 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
171 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
172 }
173 try
174 {
175 return formatJson( "OK", CampaignService.getInstance( ).isBeforeBeginning( phase ),
176 CampaignService.getInstance( ).start( phase ) + " ==> " + CampaignService.getInstance( ).end( phase ) );
177 }
178 catch( NoSuchPhaseException e )
179 {
180 AppLogService.error( e );
181 return formatJson( "KO", false );
182 }
183 }
184
185
186
187
188
189
190
191 @GET
192 @Path( "{campaign}/{phase}/after-beginning" )
193 @Produces( MediaType.APPLICATION_JSON )
194 public String isAfterBeginning( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign, @PathParam( "phase" ) String phase )
195 throws ServletException
196 {
197 if ( !isRequestAuthenticated( request ) )
198 {
199 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
200 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
201 }
202 try
203 {
204 return formatJson( "OK", CampaignService.getInstance( ).isAfterBeginning( campaign, phase ),
205 CampaignService.getInstance( ).start( campaign, phase ) + " ==> " + CampaignService.getInstance( ).end( campaign, phase ) );
206 }
207 catch( NoSuchPhaseException e )
208 {
209 AppLogService.error( e );
210 return formatJson( "KO", false );
211 }
212 }
213
214
215
216
217
218
219
220 @GET
221 @Path( "{phase}/after-beginning" )
222 @Produces( MediaType.APPLICATION_JSON )
223 public String isAfterBeginning( @Context HttpServletRequest request, @PathParam( "phase" ) String phase ) throws ServletException
224 {
225 if ( !isRequestAuthenticated( request ) )
226 {
227 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
228 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
229 }
230 try
231 {
232 return formatJson( "OK", CampaignService.getInstance( ).isAfterBeginning( phase ),
233 CampaignService.getInstance( ).start( phase ) + " ==> " + CampaignService.getInstance( ).end( phase ) );
234 }
235 catch( NoSuchPhaseException e )
236 {
237 AppLogService.error( e );
238 return formatJson( "KO", false );
239 }
240 }
241
242
243
244
245
246
247
248 @GET
249 @Path( "{campaign}/{phase}/during" )
250 @Produces( MediaType.APPLICATION_JSON )
251 public String isDuring( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign, @PathParam( "phase" ) String phase )
252 throws ServletException
253 {
254 if ( !isRequestAuthenticated( request ) )
255 {
256 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
257 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
258 }
259 try
260 {
261 return formatJson( "OK", CampaignService.getInstance( ).isDuring( campaign, phase ),
262 CampaignService.getInstance( ).start( campaign, phase ) + " ==> " + CampaignService.getInstance( ).end( campaign, phase ) );
263 }
264 catch( NoSuchPhaseException e )
265 {
266 AppLogService.error( e );
267 return formatJson( "KO", false );
268 }
269 }
270
271
272
273
274
275
276
277 @GET
278 @Path( "{phase}/during" )
279 @Produces( MediaType.APPLICATION_JSON )
280 public String isDuring( @Context HttpServletRequest request, @PathParam( "phase" ) String phase ) throws ServletException
281 {
282 if ( !isRequestAuthenticated( request ) )
283 {
284 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
285 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
286 }
287 try
288 {
289 return formatJson( "OK", CampaignService.getInstance( ).isDuring( phase ),
290 CampaignService.getInstance( ).start( phase ) + " ==> " + CampaignService.getInstance( ).end( phase ) );
291 }
292 catch( NoSuchPhaseException e )
293 {
294 AppLogService.error( e );
295 return formatJson( "KO", false );
296 }
297 }
298
299
300
301
302
303
304
305 @GET
306 @Path( "{campaign}/{phase}/before-end" )
307 @Produces( MediaType.APPLICATION_JSON )
308 public String isBeforeEnd( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign, @PathParam( "phase" ) String phase )
309 throws ServletException
310 {
311 if ( !isRequestAuthenticated( request ) )
312 {
313 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
314 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
315 }
316 try
317 {
318 return formatJson( "OK", CampaignService.getInstance( ).isBeforeEnd( campaign, phase ),
319 CampaignService.getInstance( ).start( campaign, phase ) + " ==> " + CampaignService.getInstance( ).end( campaign, phase ) );
320 }
321 catch( NoSuchPhaseException e )
322 {
323 AppLogService.error( e );
324 return formatJson( "KO", false );
325 }
326 }
327
328
329
330
331
332
333
334 @GET
335 @Path( "{phase}/before-end" )
336 @Produces( MediaType.APPLICATION_JSON )
337 public String isBeforeEnd( @Context HttpServletRequest request, @PathParam( "phase" ) String phase ) throws ServletException
338 {
339 if ( !isRequestAuthenticated( request ) )
340 {
341 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
342 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
343 }
344 try
345 {
346 return formatJson( "OK", CampaignService.getInstance( ).isBeforeEnd( phase ),
347 CampaignService.getInstance( ).start( phase ) + " ==> " + CampaignService.getInstance( ).end( phase ) );
348 }
349 catch( NoSuchPhaseException e )
350 {
351 AppLogService.error( e );
352 return formatJson( "KO", false );
353 }
354 }
355
356
357
358
359
360
361
362 @GET
363 @Path( "{campaign}/{phase}/after-end" )
364 @Produces( MediaType.APPLICATION_JSON )
365 public String isAfterEnd( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign, @PathParam( "phase" ) String phase )
366 throws ServletException
367 {
368 if ( !isRequestAuthenticated( request ) )
369 {
370 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
371 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
372 }
373 try
374 {
375 return formatJson( "OK", CampaignService.getInstance( ).isAfterEnd( campaign, phase ),
376 CampaignService.getInstance( ).start( campaign, phase ) + " ==> " + CampaignService.getInstance( ).end( campaign, phase ) );
377 }
378 catch( NoSuchPhaseException e )
379 {
380 AppLogService.error( e );
381 return formatJson( "KO", false );
382 }
383 }
384
385
386
387
388
389
390
391 @GET
392 @Path( "{phase}/after-end" )
393 @Produces( MediaType.APPLICATION_JSON )
394 public String isAfterEnd( @Context HttpServletRequest request, @PathParam( "phase" ) String phase ) throws ServletException
395 {
396 if ( !isRequestAuthenticated( request ) )
397 {
398 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
399 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
400 }
401 try
402 {
403 return formatJson( "OK", CampaignService.getInstance( ).isAfterEnd( phase ),
404 CampaignService.getInstance( ).start( phase ) + " ==> " + CampaignService.getInstance( ).end( phase ) );
405 }
406 catch( NoSuchPhaseException e )
407 {
408 AppLogService.error( e );
409 return formatJson( "KO", false );
410 }
411 }
412
413
414
415
416
417
418
419
420
421
422
423
424 @GET
425 @Path( "{campaign}/all-areas" )
426 @Produces( MediaType.APPLICATION_JSON )
427 public String getCampaignAllAreas( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign ) throws ServletException
428 {
429 if ( !isRequestAuthenticated( request ) )
430 {
431 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
432 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
433 }
434 try
435 {
436 return formatJson( "OK", CampaignService.getInstance( ).getAllAreas( campaign ) );
437 }
438 catch( NoSuchPhaseException e )
439 {
440 AppLogService.error( e );
441 return formatJson( "KO", false );
442 }
443 }
444
445
446
447
448
449
450
451 @GET
452 @Path( "all-areas" )
453 @Produces( MediaType.APPLICATION_JSON )
454 public String getLastCampaignAllAreas( @Context HttpServletRequest request ) throws ServletException
455 {
456 if ( !isRequestAuthenticated( request ) )
457 {
458 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
459 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
460 }
461 try
462 {
463 return formatJson( "OK", CampaignService.getInstance( ).getAllAreas( ) );
464 }
465 catch( NoSuchPhaseException e )
466 {
467 AppLogService.error( e );
468 return formatJson( "KO", false );
469 }
470 }
471
472
473
474
475
476
477
478 @GET
479 @Path( "{campaign}/localized-areas" )
480 @Produces( MediaType.APPLICATION_JSON )
481 public String getCampaignLocalizedAreas( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign ) throws ServletException
482 {
483 if ( !isRequestAuthenticated( request ) )
484 {
485 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
486 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
487 }
488 try
489 {
490 return formatJson( "OK", CampaignService.getInstance( ).getLocalizedAreas( campaign ) );
491 }
492 catch( NoSuchPhaseException e )
493 {
494 AppLogService.error( e );
495 return formatJson( "KO", false );
496 }
497 }
498
499
500
501
502
503
504
505 @GET
506 @Path( "localized-areas" )
507 @Produces( MediaType.APPLICATION_JSON )
508 public String getLastCampaignLocalizedAreas( @Context HttpServletRequest request ) throws ServletException
509 {
510 if ( !isRequestAuthenticated( request ) )
511 {
512 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
513 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
514 }
515 try
516 {
517 return formatJson( "OK", CampaignService.getInstance( ).getLocalizedAreas( ) );
518 }
519 catch( NoSuchPhaseException e )
520 {
521 AppLogService.error( e );
522 return formatJson( "KO", false );
523 }
524 }
525
526
527
528
529
530
531
532 @GET
533 @Path( "{campaign}/whole-area" )
534 @Produces( MediaType.APPLICATION_JSON )
535 public String getCampaignWholeArea( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign ) throws ServletException
536 {
537 if ( !isRequestAuthenticated( request ) )
538 {
539 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
540 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
541 }
542 try
543 {
544 return formatJson( "OK", CampaignService.getInstance( ).getWholeArea( campaign ) );
545 }
546 catch( NoSuchPhaseException e )
547 {
548 AppLogService.error( e );
549 return formatJson( "KO", false );
550 }
551 }
552
553
554
555
556
557
558
559 @GET
560 @Path( "whole-area" )
561 @Produces( MediaType.APPLICATION_JSON )
562 public String getLastCampaignWholeArea( @Context HttpServletRequest request ) throws ServletException
563 {
564 if ( !isRequestAuthenticated( request ) )
565 {
566 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
567 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
568 }
569 try
570 {
571 String result = CampaignService.getInstance( ).getWholeArea( );
572 if ( result.equals( "" ) )
573 {
574 return formatJson( "KO", result );
575 }
576 return formatJson( "OK", result );
577 }
578 catch( NoSuchPhaseException e )
579 {
580 AppLogService.error( e );
581 return formatJson( "KO", false );
582 }
583 }
584
585
586
587
588
589
590
591
592
593
594
595
596 @GET
597 @Path( "{campaign}/themes" )
598 @Produces( MediaType.APPLICATION_JSON )
599 public String getCampaignThemes( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign ) throws ServletException
600 {
601 if ( !isRequestAuthenticated( request ) )
602 {
603 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
604 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
605 }
606 try
607 {
608 return formatJson( "OK", CampaignService.getInstance( ).getThemes( campaign ) );
609 }
610 catch( NoSuchPhaseException e )
611 {
612 AppLogService.error( e );
613 return formatJson( "KO", false );
614 }
615 }
616
617
618
619
620
621
622
623 @GET
624 @Path( "themes" )
625 @Produces( MediaType.APPLICATION_JSON )
626 public String getCampaignThemes( @Context HttpServletRequest request ) throws ServletException
627 {
628 if ( !isRequestAuthenticated( request ) )
629 {
630 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
631 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
632 }
633 try
634 {
635 return formatJson( "OK", CampaignService.getInstance( ).getThemes( ) );
636 }
637 catch( NoSuchPhaseException e )
638 {
639 AppLogService.error( e );
640 return formatJson( "KO", false );
641 }
642 }
643
644
645
646
647
648
649
650 @GET
651 @Path( "{campaign}/themes-front-rgb" )
652 @Produces( MediaType.APPLICATION_JSON )
653 public String getCampaignThemesFrontRgb( @Context HttpServletRequest request, @PathParam( "campaign" ) String campaign ) throws ServletException
654 {
655 if ( !isRequestAuthenticated( request ) )
656 {
657 AppLogService.error( LOG_UNAUTHENTICATED_REQUEST );
658 throw new ServletException( LOG_UNAUTHENTICATED_REQUEST );
659 }
660 try
661 {
662 return formatJson( "OK", CampaignService.getInstance( ).getThemesFrontRgb( campaign ) );
663 }
664 catch( NoSuchPhaseException e )
665 {
666 AppLogService.error( e );
667 return formatJson( "KO", false );
668 }
669 }
670
671 }