View Javadoc
1   /*
2    * Copyright (c) 2002-2014, 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.directory.modules.rest.service;
35  
36  import fr.paris.lutece.plugins.directory.business.Directory;
37  import fr.paris.lutece.plugins.directory.business.Field;
38  import fr.paris.lutece.plugins.directory.business.IEntry;
39  import fr.paris.lutece.plugins.directory.business.Record;
40  import fr.paris.lutece.plugins.directory.business.RecordField;
41  import fr.paris.lutece.plugins.directory.utils.DirectoryErrorException;
42  import fr.paris.lutece.portal.web.upload.MultipartHttpServletRequest;
43  
44  import org.apache.commons.fileupload.FileUploadBase.SizeLimitExceededException;
45  import org.apache.commons.fileupload.FileUploadException;
46  
47  import java.util.List;
48  import java.util.Map;
49  
50  import javax.servlet.ServletRequest;
51  import javax.servlet.http.HttpServletRequest;
52  
53  
54  /**
55   *
56   * IDirectoryRestService
57   *
58   */
59  public interface IDirectoryRestService
60  {
61      // GET
62  
63      /**
64       * Gets the record
65       * @param nIdRecord resource id
66       * @param request the HTTP request
67       * @return the record
68       * @throws DirectoryRestException if occurs
69       * @throws DirectoryErrorException if occurs
70       */
71      Record getRecord( int nIdRecord, HttpServletRequest request )
72          throws DirectoryRestException, DirectoryErrorException;
73  
74       /**
75       * Finds the list
76       * @param nIdDirectory the directory id
77       * @param request the HTTP request
78       * @return the record list
79       * @throws DirectoryRestException if occurs
80       * @throws DirectoryErrorException if occurs
81       */
82      List<Record> getRecordsList( int nIdDirectory, HttpServletRequest request )
83          throws DirectoryRestException, DirectoryErrorException;
84  
85      /**
86       * Get the list of entries from the record
87       * @param record the record
88       * @return a list of {@link IEntry}
89       */
90      List<IEntry> getEntries( Record record );
91  
92      /**
93       * Get the ids entry from the parameters of the request.
94       * <br />
95       * If there is no ids entry in the parameter, then get all entries.
96       * @param nIdDirectory the id directory
97       * @param request the HTTP request
98       * @return the list of id entry
99       */
100     List<Integer> getIdsEntry( int nIdDirectory, HttpServletRequest request );
101 
102     /**
103      * Get all entries
104      * @param nIdDirectory the id directory
105      * @return the list of id entry
106      */
107     List<Integer> getIdsEntry( int nIdDirectory );
108 
109     /**
110      * Get the directory given the id directory
111      * @param nIdDirectory the id directory
112      * @return the directory
113      */
114     Directory getDirectory( int nIdDirectory );
115 
116     /**
117      * Get the list of directories
118      * @return the list of directories
119      */
120     List<Directory> getDirectoriesList(  );
121 
122     /**
123      * Get the map of id entry - List de Record Field
124      * @param record the record
125      * @return the map
126      */
127     Map<String, List<RecordField>> getMapIdEntryListRecordField( Record record );
128 
129     // ACTION
130 
131     /**
132      * Add a record in a directory with the parameters given if they match
133      * @param strIdDirectory the directory id
134      * @param request the HTTP request
135      * @return the record
136      * @throws DirectoryErrorException exception if there is an error
137      */
138     Record addToDirectory( String strIdDirectory, ServletRequest request )
139         throws DirectoryErrorException;
140 
141     /**
142      * Creates or updates the record
143      * @param request the request
144      * @return the record created or updated
145      * @throws DirectoryErrorException if occurs
146      * @throws DirectoryRestException if occurs
147      */
148     Record insertOrCompleteRecord( HttpServletRequest request )
149         throws DirectoryErrorException, DirectoryRestException;
150 
151     /**
152      * delete the record
153      * @param nIdRecord the id record
154      * @param request the HTTP request
155      * @return the record deleted
156      * @throws DirectoryErrorException if occurs
157      * @throws DirectoryRestException if occurs
158      */
159     String deleteRecord( int nIdRecord, HttpServletRequest request )
160         throws DirectoryErrorException, DirectoryRestException;
161 
162     /**
163      * Gets record fields values from the request and complete the record for asynchronous record creation.
164      * This method is <b>NOT</b> a modification of the record.
165      * @param nIdRecord the id of the record to complete
166      * @param request the request
167      * @return the stored record
168      * @throws DirectoryErrorException if a directory exception occurs
169      * @throws DirectoryRestException if a rest exception occurs
170      */
171     Record completeRecord( int nIdRecord, ServletRequest request )
172         throws DirectoryErrorException, DirectoryRestException;
173 
174     /**
175      * Update record
176      * @param request the HTTP request
177      * @return the record
178      * @throws DirectoryErrorException exception if there is an error
179      * @throws DirectoryRestException exception if there is an error
180      */
181     Record updateRecord( HttpServletRequest request ) throws DirectoryRestException, DirectoryErrorException;
182 
183     /**
184      * Convert the HTTP request to a {@link MultipartHttpServletRequest}
185      * @param request the HTTP request
186      * @return a {@link MultipartHttpServletRequest}, null if the content is not multipart
187      * @throws SizeLimitExceededException exception if the file size is too big
188      * @throws FileUploadException exception if an unknown error has occurred
189      */
190     MultipartHttpServletRequest convertRequest( HttpServletRequest request )
191         throws SizeLimitExceededException, FileUploadException;
192 }