+ * Restores a previous version for a file.
+ *
+ * @param req the HTTP request
+ * @param resp the HTTP response
+ * @param path the resource path
+ * @param version the version number to restore
+ * @throws IOException if an I/O error occurs
+ */
+ private void restoreVersion(HttpServletRequest req, HttpServletResponse resp, String path, String version) throws IOException {
+ User user = getUser(req);
+ User owner = getOwner(req);
+ Object resource = null;
+ try {
+ resource = getService().getResourceAtPath(owner.getId(), path, true);
+ } catch (ObjectNotFoundException e) {
+ resp.sendError(HttpServletResponse.SC_NOT_FOUND, path);
+ return;
+ } catch (RpcException e) {
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path);
+ return;
+ }
+ if (resource instanceof FolderDTO) {
+ resp.sendError(HttpServletResponse.SC_CONFLICT);
+ return;
+ }
+
+ try {
+ FileHeaderDTO file = (FileHeaderDTO) resource;
+ int oldVersion = Integer.parseInt(version);
+ getService().restoreVersion(user.getId(), file.getId(), oldVersion);
+ } catch (InsufficientPermissionsException e) {
+ resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ } catch (ObjectNotFoundException e) {
+ resp.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
+ } catch (RpcException e) {
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, path);
+ } catch (GSSIOException e) {
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
+ } catch (QuotaExceededException e) {
+ resp.sendError(HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE, e.getMessage());
+ } catch (NumberFormatException e) {
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, e.getMessage());
+ }
+ }
+
+ /**