View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de 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  package fr.paris.lutece.plugins.archive.modules.rest.rs;
35  
36  import fr.paris.lutece.plugins.archive.service.archive.IArchiveService;
37  import fr.paris.lutece.plugins.rest.service.RestConstants;
38  import fr.paris.lutece.portal.service.util.AppLogService;
39  
40  import javax.ws.rs.FormParam;
41  import javax.ws.rs.GET;
42  import javax.ws.rs.POST;
43  import javax.ws.rs.Path;
44  import javax.ws.rs.Produces;
45  import javax.ws.rs.QueryParam;
46  import javax.ws.rs.core.MediaType;
47  
48  
49  /**
50   * ArchiveRest
51   */
52  @Path( RestConstants.BASE_PATH + "archive" )
53  /**
54   *
55   * @author pierre
56   */
57  public class ArchiveRest
58  {
59      private IArchiveService archiveService;
60  
61      @POST
62      @Path( "generateArchive" )
63      @Produces( MediaType.TEXT_PLAIN )
64      public String generateArchive( @FormParam( "folder_to_archive" )
65      String strFolderToArchive, @FormParam( "archive_destination" )
66      String strArchiveDestination, @FormParam( "archive_name" )
67      String strArchiveName, @FormParam( "archive_type" )
68      String strArchiveType )
69      {
70          return Integer.toString( archiveService.generateArchive( strFolderToArchive, strArchiveDestination,
71                  strArchiveName, strArchiveType ) );
72      }
73  
74      @POST
75      @Path( "informationArchive" )
76      @Produces( MediaType.TEXT_PLAIN )
77      public String informationArchive(@FormParam( "archive_item_key" )
78      String archiveItemKey )
79      {
80          {
81              int nArchiveItemKey = -1;
82  
83              try
84              {
85                  nArchiveItemKey = Integer.parseInt( archiveItemKey );
86              }
87              catch ( NumberFormatException e )
88              {
89                  AppLogService.error( e );
90              }
91  
92              return archiveService.informationArchive( nArchiveItemKey );
93          }
94      }
95  
96      @POST
97      @Path( "removeArchive" )
98      @Produces( MediaType.TEXT_PLAIN )
99      public void removeArchive( @FormParam( "archive_item_key" )
100     String archiveItemKey )
101     {
102         {
103             int nArchiveItemKey = -1;
104 
105             try
106             {
107                 nArchiveItemKey = Integer.parseInt( archiveItemKey );
108             }
109             catch ( NumberFormatException e )
110             {
111                 AppLogService.error( e );
112             }
113 
114             archiveService.removeArchive( nArchiveItemKey );
115         }
116     }
117 
118     public void setArchiveService( IArchiveService archiveService )
119     {
120         this.archiveService = archiveService;
121     }
122 }