- GET on the 'others' namespace returns the username of the user sharing the resource
- GET on the 'groups' namespace returns the name of the group
- GET on files and folders returns the parent folder as well
private UserDTO owner;
/**
+ * The folder that contains this file.
+ */
+ private FolderDTO folder;
+
+ /**
* The size of the file
*/
private long fileSize;
public String getURI() {
return PATH_GSS + owner.getUsername() + PATH_FILES + getPath();
}
+
+
+ /**
+ * Retrieve the folder.
+ *
+ * @return the folder
+ */
+ public FolderDTO getFolder() {
+ return folder;
+ }
+
+
+ /**
+ * Modify the folder.
+ *
+ * @param aFolder the folder to set
+ */
+ public void setFolder(FolderDTO aFolder) {
+ folder = aFolder;
+ }
}
f.setId(id);\r
f.setName(name);\r
f.setPath(getPath());\r
+ f.setFolder(folder.getDTO());\r
f.setVersioned(versioned);\r
f.setVersion(currentBody.getVersion());\r
f.setOwner(owner.getDTO());\r
put("createdBy", folder.getAuditInfo().getCreatedBy().getUsername()).
put("creationDate", folder.getAuditInfo().getCreationDate().getTime()).
put("deleted", folder.isDeleted());
+ if (folder.getParent() != null)
+ json.put("parent", folder.getParent().getURI());
if (folder.getAuditInfo().getModifiedBy() != null)
json.put("modifiedBy", folder.getAuditInfo().getModifiedBy().getUsername()).
put("modificationDate", folder.getAuditInfo().getModificationDate().getTime());
put("version", oldBody != null ? oldBody.getVersion() : file.getVersion()).
put("readForAll", file.isReadForAll()).
put("tags", file.getTags()).
+ put("folder", file.getFolder().getURI()).
put("deleted", file.isDeleted());
if (oldBody != null)
json.put("createdBy", oldBody.getAuditInfo().getCreatedBy().getUsername()).
resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
- if (path.equals("/")) {
- // Request to serve all groups
- List<GroupDTO> groups;
+ if (path.equals("/"))
+ // Request to serve all groups
try {
- groups = getService().getGroups(owner.getId());
+ List<GroupDTO> groups = getService().getGroups(owner.getId());
+ JSONArray json = new JSONArray();
+ for (GroupDTO group: groups) {
+ JSONObject j = new JSONObject();
+ j.put("name", group.getName()).
+ put("uri", parentUrl + group.getName());
+ json.put(j);
+ }
+
+ sendJson(req, resp, json.toString());
} catch (ObjectNotFoundException e) {
logger.error("User not found", e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
logger.error("", e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
- }
- JSONArray json = new JSONArray();
- for (GroupDTO group: groups)
- json.put(parentUrl + group.getName());
-
- sendJson(req, resp, json.toString());
- } else {
+ } catch (JSONException e) {
+ logger.error("", e);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return;
+ }
+ else {
// Chop any trailing slash
path = path.endsWith("/")? path.substring(0, path.length()-1): path;
// Chop any leading slash
JSONArray json = new JSONArray();
List<UserDTO> others = getService().getUsersSharingFoldersForUser(owner.getId());
- for (UserDTO u: others)
- json.put(parentUrl + u.getUsername());
+ for (UserDTO u: others) {
+ JSONObject j = new JSONObject();
+ j.put("username", u.getUsername()).
+ put("uri", parentUrl + u.getUsername());
+ json.put(j);
+ }
sendJson(req, resp, json.toString());
} catch (ObjectNotFoundException e) {
logger.error("", e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
+ } catch (JSONException e) {
+ logger.error("", e);
+ resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ return;
}
else
try {