View Javadoc
1   /*
2    * Copyright (c) 2002-2020, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  /*
35   /*
36   * Copyright (c) 2002-2017, Mairie de Paris
37   * All rights reserved.
38   *
39   * Redistribution and use in source and binary forms, with or without
40   * modification, are permitted provided that the following conditions
41   * are met:
42   *
43   *  1. Redistributions of source code must retain the above copyright notice
44   *     and the following disclaimer.
45   *
46   *  2. Redistributions in binary form must reproduce the above copyright notice
47   *     and the following disclaimer in the documentation and/or other materials
48   *     provided with the distribution.
49   *
50   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
51   *     contributors may be used to endorse or promote products derived from
52   *     this software without specific prior written permission.
53   *
54   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
55   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
58   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
59   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
60   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
61   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
62   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
63   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
64   * POSSIBILITY OF SUCH DAMAGE.
65   *
66   * License 1.0
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      // * CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN *
93      // * CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN CAMPAIGN *
94      // *********************************************************************************************
95  
96      /**
97       * Returns the list of campaigns
98       * 
99       * @return the List of campaigns
100      * @throws ServletException
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     // * PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE *
125     // * PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE PHASE *
126     // *********************************************************************************************
127 
128     /**
129      * get isBeforeBeginning of a phase of a campaign
130      * 
131      * @return the response of the request isBeforeBeginning for a phase of a campaign
132      * @throws ServletException
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      * get isBeforeBeginning of a phase of last campaign
159      * 
160      * @return the response of the request isBeforeBeginning for a phase of the last campaign
161      * @throws ServletException
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      * get isAfterBeginning of a phase of a campaign
187      * 
188      * @return the response of the request isAfterBeginning for a phase of a campaign
189      * @throws ServletException
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      * get isAfterBeginning of a phase of last campaign
216      * 
217      * @return the response of the request isAfterBeginning for a phase of the last campaign
218      * @throws ServletException
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      * get isDuring of a phase of a campaign
244      * 
245      * @return the response of the request isDuring for a phase of a campaign
246      * @throws ServletException
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      * get isDuring of a phase of last campaign
273      * 
274      * @return the response of the request isDuring for a phase of last campaign
275      * @throws ServletException
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      * get isBeforeEnd of a phase of a campaign
301      * 
302      * @return the response of the request isBeforeEnd for a phase of a campaign
303      * @throws ServletException
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      * get isBeforeEnd of a phase of last campaign
330      * 
331      * @return the response of the request isBeforeEnd for a phase of the last campaign
332      * @throws ServletException
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      * get isAfterEnd of a phase of a campaign
358      * 
359      * @return the response of the request isAfterEnd for a phase of a campaign
360      * @throws ServletException
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      * get isAfterEnd of a phase of last campaign
387      * 
388      * @return the response of the request isAfterEnd for a phase of the last campaign
389      * @throws ServletException
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     // * AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA *
415     // * AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA AREA *
416     // *********************************************************************************************
417 
418     /**
419      * get all areas of a campaign
420      *
421      * @return the response of the request getAllAreas for a campaign
422      * @throws ServletException
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      * get localized areas of last campaign
447      *
448      * @return the response of the request getAllAreas for the last campaign
449      * @throws ServletException
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      * get localized areas of a campaign
474      *
475      * @return the response of the request getLocalizedAreas for a campaign
476      * @throws ServletException
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      * get localized areas of last campaign
501      *
502      * @return the response of the request getLocalizedAreas for the last campaign
503      * @throws ServletException
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      * get area whole of a campaign
528      *
529      * @return the response of the request getAreas for a campaign
530      * @throws ServletException
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      * get areas of last campaign
555      *
556      * @return the response of the request getAreas for the last campaign
557      * @throws ServletException
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     // * THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME *
587     // * THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME THEME *
588     // *********************************************************************************************
589 
590     /**
591      * get themes of a campaign
592      *
593      * @return the response of the request getThemes for a campaign
594      * @throws ServletException
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      * get themes of last campaign
619      *
620      * @return the response of the request getThemes for the last campaign
621      * @throws ServletException
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      * get themes front rgb of a campaign
646      *
647      * @return the response of the request getThemes for a campaign
648      * @throws ServletException
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 }