1010import com .eclipsesource .json .JsonObject ;
1111import com .eclipsesource .json .JsonValue ;
1212
13+ /**
14+ * Represents a folder on Box. This class can be used to iterate through a folder's contents, collaborate a folder with
15+ * another user or group, and perform other common folder operations (move, copy, delete, etc.).
16+ */
1317public final class BoxFolder extends BoxItem implements Iterable <BoxItem > {
1418 private static final String UPLOAD_FILE_URL_BASE = "https://upload.box.com/api/2.0/" ;
1519 private static final URLTemplate CREATE_FOLDER_URL = new URLTemplate ("folders" );
@@ -22,16 +26,32 @@ public final class BoxFolder extends BoxItem implements Iterable<BoxItem> {
2226
2327 private final URL folderURL ;
2428
29+ /**
30+ * Constructs a BoxFolder for a folder with a given ID.
31+ * @param api the API connection to be used by the folder.
32+ * @param id the ID of the folder.
33+ */
2534 public BoxFolder (BoxAPIConnection api , String id ) {
2635 super (api , id );
2736
2837 this .folderURL = FOLDER_INFO_URL_TEMPLATE .build (this .getAPI ().getBaseURL (), this .getID ());
2938 }
3039
40+ /**
41+ * Gets the current user's root folder.
42+ * @param api the API connection to be used by the folder.
43+ * @return the user's root folder.
44+ */
3145 public static BoxFolder getRootFolder (BoxAPIConnection api ) {
3246 return new BoxFolder (api , "0" );
3347 }
3448
49+ /**
50+ * Adds a collaborator to this folder.
51+ * @param collaborator the collaborator to add.
52+ * @param role the role of the collaborator.
53+ * @return info about the new collaboration.
54+ */
3555 public BoxCollaboration .Info collaborate (BoxCollaborator collaborator , BoxCollaboration .Role role ) {
3656 JsonObject accessibleByField = new JsonObject ();
3757 accessibleByField .add ("id" , collaborator .getID ());
@@ -45,6 +65,13 @@ public BoxCollaboration.Info collaborate(BoxCollaborator collaborator, BoxCollab
4565 return this .collaborate (accessibleByField , role );
4666 }
4767
68+ /**
69+ * Adds a collaborator to this folder. An email will be sent to the collaborator if they don't already have a Box
70+ * account.
71+ * @param email the email address of the collaborator to add.
72+ * @param role the role of the collaborator.
73+ * @return info about the new collaboration.
74+ */
4875 public BoxCollaboration .Info collaborate (String email , BoxCollaboration .Role role ) {
4976 JsonObject accessibleByField = new JsonObject ();
5077 accessibleByField .add ("login" , email );
@@ -76,6 +103,10 @@ private BoxCollaboration.Info collaborate(JsonObject accessibleByField, BoxColla
76103 return info ;
77104 }
78105
106+ /**
107+ * Gets information about all of the collaborations for this folder.
108+ * @return a collection of information about the collaborations for this folder.
109+ */
79110 public Collection <BoxCollaboration .Info > getCollaborations () {
80111 BoxAPIConnection api = this .getAPI ();
81112 URL url = GET_COLLABORATIONS_URL .build (api .getBaseURL (), this .getID ());
@@ -114,6 +145,10 @@ public BoxFolder.Info getInfo(String... fields) {
114145 return new Info (response .getJSON ());
115146 }
116147
148+ /**
149+ * Updates the information about this folder with any info fields that have been modified locally.
150+ * @param info the updated info.
151+ */
117152 public void updateInfo (BoxFolder .Info info ) {
118153 BoxJSONRequest request = new BoxJSONRequest (this .getAPI (), this .folderURL , "PUT" );
119154 request .setBody (info .getPendingChanges ());
@@ -148,6 +183,11 @@ public BoxFolder.Info copy(BoxFolder destination, String newName) {
148183 return copiedFolder .new Info (responseJSON );
149184 }
150185
186+ /**
187+ * Creates a new child folder inside this folder.
188+ * @param name the new folder's name.
189+ * @return the created folder.
190+ */
151191 public BoxFolder createFolder (String name ) {
152192 JsonObject parent = new JsonObject ();
153193 parent .add ("id" , this .getID ());
@@ -165,22 +205,26 @@ public BoxFolder createFolder(String name) {
165205 return new BoxFolder (this .getAPI (), createdFolder .get ("id" ).asString ());
166206 }
167207
208+ /**
209+ * Deletes this folder, optionally recursively deleting all of its contents.
210+ * @param recursive true to recursively delete this folder's contents; otherwise false.
211+ */
168212 public void delete (boolean recursive ) {
169213 URL url = DELETE_FOLDER_URL .build (this .getAPI ().getBaseURL (), this .getID (), recursive );
170214 BoxAPIRequest request = new BoxAPIRequest (this .getAPI (), url , "DELETE" );
171215 BoxAPIResponse response = request .send ();
172216 response .disconnect ();
173217 }
174218
219+ /**
220+ * Moves this folder to another folder.
221+ * @param destination the destination folder.
222+ */
175223 public void move (BoxFolder destination ) {
176- this .move (destination .getID ());
177- }
178-
179- public void move (String destinationID ) {
180224 BoxJSONRequest request = new BoxJSONRequest (this .getAPI (), this .folderURL , "PUT" );
181225
182226 JsonObject parent = new JsonObject ();
183- parent .add ("id" , destinationID );
227+ parent .add ("id" , destination . getID () );
184228
185229 JsonObject updateInfo = new JsonObject ();
186230 updateInfo .add ("parent" , parent );
@@ -190,6 +234,10 @@ public void move(String destinationID) {
190234 response .disconnect ();
191235 }
192236
237+ /**
238+ * Renames this folder.
239+ * @param newName the new name of the folder.
240+ */
193241 public void rename (String newName ) {
194242 BoxJSONRequest request = new BoxJSONRequest (this .getAPI (), this .folderURL , "PUT" );
195243
@@ -201,13 +249,27 @@ public void rename(String newName) {
201249 response .disconnect ();
202250 }
203251
252+ /**
253+ * Uploads a new file to this folder.
254+ * @param fileContent a stream containing the contents of the file to upload.
255+ * @param name the name to give the uploaded file.
256+ * @return the uploaded file.
257+ */
204258 public BoxFile uploadFile (InputStream fileContent , String name ) {
205259 FileUploadParams uploadInfo = new FileUploadParams ()
206260 .setContent (fileContent )
207261 .setName (name );
208262 return this .uploadFile (uploadInfo );
209263 }
210264
265+ /**
266+ * Uploads a new file to this folder while reporting the progress to a ProgressListener.
267+ * @param fileContent a stream containing the contents of the file to upload.
268+ * @param name the name to give the uploaded file.
269+ * @param fileSize the size of the file used for determining the progress of the upload.
270+ * @param listener a listener for monitoring the upload's progress.
271+ * @return the uploaded file.
272+ */
211273 public BoxFile uploadFile (InputStream fileContent , String name , long fileSize , ProgressListener listener ) {
212274 FileUploadParams uploadInfo = new FileUploadParams ()
213275 .setContent (fileContent )
@@ -217,6 +279,11 @@ public BoxFile uploadFile(InputStream fileContent, String name, long fileSize, P
217279 return this .uploadFile (uploadInfo );
218280 }
219281
282+ /**
283+ * Uploads a new file to this folder with custom upload settings.
284+ * @param uploadInfo the custom upload settings.
285+ * @return the uploaded file.
286+ */
220287 public BoxFile uploadFile (FileUploadParams uploadInfo ) {
221288 URL uploadURL = UPLOAD_FILE_URL .build (UPLOAD_FILE_URL_BASE );
222289 BoxMultipartRequest request = new BoxMultipartRequest (getAPI (), uploadURL );
@@ -249,19 +316,37 @@ public BoxFile uploadFile(FileUploadParams uploadInfo) {
249316 return new BoxFile (getAPI (), uploadedFileID );
250317 }
251318
319+ /**
320+ * Returns an iterator over the items in this folder.
321+ * @return an iterator over the items in this folder.
322+ */
252323 public Iterator <BoxItem > iterator () {
253324 return new BoxItemIterator (BoxFolder .this .getAPI (), BoxFolder .this .getID ());
254325 }
255326
327+ /**
328+ * Contains additional information about a BoxFolder.
329+ */
256330 public class Info extends BoxItem .Info {
331+ /**
332+ * Constructs an empty Info object.
333+ */
257334 public Info () {
258335 super ();
259336 }
260337
338+ /**
339+ * Constructs an Info object by parsing information from a JSON string.
340+ * @param json the JSON string to parse.
341+ */
261342 public Info (String json ) {
262343 super (json );
263344 }
264345
346+ /**
347+ * Constructs an Info object using an already parsed JSON object.
348+ * @param jsonObject the parsed JSON object.
349+ */
265350 protected Info (JsonObject jsonObject ) {
266351 super (jsonObject );
267352 }
0 commit comments