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.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
51
52 @Path( RestConstants.BASE_PATH + "archive" )
53
54
55
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 }