Revision 77f75ac4 gss/src/gr/ebs/gss/server/rest/FilesHandler.java
b/gss/src/gr/ebs/gss/server/rest/FilesHandler.java | ||
---|---|---|
340 | 340 |
long contentLength = -1L; |
341 | 341 |
|
342 | 342 |
if (file != null) { |
343 |
// Parse range specifier |
|
343 |
// Parse range specifier.
|
|
344 | 344 |
ranges = parseRange(req, resp, file, oldBody); |
345 | 345 |
// ETag header |
346 | 346 |
resp.setHeader("ETag", getETag(file, oldBody)); |
347 |
// Last-Modified header |
|
347 |
// Last-Modified header.
|
|
348 | 348 |
String lastModified = oldBody == null ? |
349 | 349 |
getLastModifiedHttp(file.getAuditInfo()) : |
350 | 350 |
getLastModifiedHttp(oldBody.getAuditInfo()); |
351 | 351 |
resp.setHeader("Last-Modified", lastModified); |
352 |
// X-GSS-Metadata header |
|
352 |
// X-GSS-Metadata header.
|
|
353 | 353 |
try { |
354 | 354 |
resp.setHeader("X-GSS-Metadata", renderJson(user, file, oldBody)); |
355 | 355 |
} catch (InsufficientPermissionsException e) { |
356 | 356 |
resp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); |
357 | 357 |
return; |
358 | 358 |
} |
359 |
// Get content length |
|
359 |
// Get content length.
|
|
360 | 360 |
contentLength = version>0 ? oldBody.getFileSize() : file.getFileSize(); |
361 | 361 |
// Special case for zero length files, which would cause a |
362 |
// (silent) ISE when setting the output buffer size |
|
362 |
// (silent) ISE when setting the output buffer size.
|
|
363 | 363 |
if (contentLength == 0L) |
364 | 364 |
content = false; |
365 |
} |
|
365 |
} else |
|
366 |
// Set the folder X-GSS-Metadata header. |
|
367 |
try { |
|
368 |
resp.setHeader("X-GSS-Metadata", renderJsonMetadata(user, folder)); |
|
369 |
} catch (InsufficientPermissionsException e) { |
|
370 |
resp.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED); |
|
371 |
return; |
|
372 |
} |
|
366 | 373 |
|
367 | 374 |
ServletOutputStream ostream = null; |
368 | 375 |
PrintWriter writer = null; |
... | ... | |
1604 | 1611 |
put("createdBy", folder.getAuditInfo().getCreatedBy().getUsername()). |
1605 | 1612 |
put("creationDate", folder.getAuditInfo().getCreationDate().getTime()). |
1606 | 1613 |
put("deleted", folder.isDeleted()); |
1614 |
if (folder.getAuditInfo().getModifiedBy() != null) |
|
1615 |
json.put("modifiedBy", folder.getAuditInfo().getModifiedBy().getUsername()). |
|
1616 |
put("modificationDate", folder.getAuditInfo().getModificationDate().getTime()); |
|
1607 | 1617 |
if (folder.getParent() != null) { |
1608 | 1618 |
JSONObject j = new JSONObject(); |
1609 | 1619 |
j.put("uri", getApiRoot() + folder.getParent().getURI()); |
1610 | 1620 |
j.put("name", folder.getParent().getName()); |
1611 | 1621 |
json.put("parent", j); |
1612 | 1622 |
} |
1613 |
if (folder.getAuditInfo().getModifiedBy() != null) |
|
1614 |
json.put("modifiedBy", folder.getAuditInfo().getModifiedBy().getUsername()). |
|
1615 |
put("modificationDate", folder.getAuditInfo().getModificationDate().getTime()); |
|
1616 | 1623 |
List<JSONObject> subfolders = new ArrayList<JSONObject>(); |
1617 | 1624 |
for (FolderDTO f: folder.getSubfolders()) |
1618 | 1625 |
if (!f.isDeleted()) { |
... | ... | |
1663 | 1670 |
|
1664 | 1671 |
/** |
1665 | 1672 |
* Return a String with a JSON representation of the metadata |
1673 |
* of the specified folder. |
|
1674 |
* @throws RpcException |
|
1675 |
* @throws InsufficientPermissionsException |
|
1676 |
* @throws ObjectNotFoundException |
|
1677 |
*/ |
|
1678 |
private String renderJsonMetadata(User user, FolderDTO folder) |
|
1679 |
throws ServletException, InsufficientPermissionsException { |
|
1680 |
// Check if the user has read permission. |
|
1681 |
try { |
|
1682 |
if (!getService().canReadFolder(user.getId(), folder.getId())) |
|
1683 |
throw new InsufficientPermissionsException(); |
|
1684 |
} catch (ObjectNotFoundException e) { |
|
1685 |
throw new ServletException(e); |
|
1686 |
} catch (RpcException e) { |
|
1687 |
throw new ServletException(e); |
|
1688 |
} |
|
1689 |
|
|
1690 |
JSONObject json = new JSONObject(); |
|
1691 |
try { |
|
1692 |
json.put("name", folder.getName()). |
|
1693 |
put("owner", folder.getOwner().getUsername()). |
|
1694 |
put("createdBy", folder.getAuditInfo().getCreatedBy().getUsername()). |
|
1695 |
put("creationDate", folder.getAuditInfo().getCreationDate().getTime()). |
|
1696 |
put("deleted", folder.isDeleted()); |
|
1697 |
if (folder.getAuditInfo().getModifiedBy() != null) |
|
1698 |
json.put("modifiedBy", folder.getAuditInfo().getModifiedBy().getUsername()). |
|
1699 |
put("modificationDate", folder.getAuditInfo().getModificationDate().getTime()); |
|
1700 |
} catch (JSONException e) { |
|
1701 |
throw new ServletException(e); |
|
1702 |
} |
|
1703 |
return json.toString(); |
|
1704 |
} |
|
1705 |
|
|
1706 |
/** |
|
1707 |
* Return a String with a JSON representation of the metadata |
|
1666 | 1708 |
* of the specified file. If an old file body is provided, then |
1667 | 1709 |
* the metadata of that particular version will be returned. |
1668 | 1710 |
* |
Also available in: Unified diff