Search in sources :

Example 21 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxFoldersManager method createFolderSharedLink.

/**
     * Create a shared link to folder.
     * 
     * @param folderId
     *            - the id of folder to create shared link on.
     * @param access
     *            - the access level of the shared link.
     * @param unshareDate
     *            - the date and time at which time the created shared link will
     *            expire; if <code>unsharedDate</code> is <code>null</code> then
     *            a non-expiring link is created.
     * @param permissions
     *            - the permissions of the created link; if
     *            <code>permissions</code> is <code>null</code> then the created
     *            shared link is create with default permissions.
     * @return The created shared link.
     */
public BoxSharedLink createFolderSharedLink(String folderId, BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions) {
    try {
        LOG.debug("Creating shared link for folder(id=" + folderId + ") with access=" + access + (unshareDate == null ? "" : " unsharedDate=" + SimpleDateFormat.getDateTimeInstance().format(unshareDate) + " permissions=" + permissions));
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (access == null) {
            throw new IllegalArgumentException("Parameter 'access' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        return folder.createSharedLink(access, unshareDate, permissions);
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 22 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxFoldersManager method createFolder.

/**
     * Create a folder in parent folder with given <code>folderName</code>.
     * 
     * @param parentFolderId
     *            - the id of parent folder.
     * @param folderName
     *            the name of created folder.
     * @return The created folder.
     */
public BoxFolder createFolder(String parentFolderId, String folderName) {
    try {
        LOG.debug("Creating folder with name '" + folderName + "' in parent_folder(id=" + parentFolderId + ")");
        if (parentFolderId == null) {
            throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null");
        }
        if (folderName == null) {
            throw new IllegalArgumentException("Paramerer 'folderName' can not be null");
        }
        BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId);
        return parentFolder.createFolder(folderName).getResource();
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 23 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxFoldersManager method moveFolder.

/**
     * Move folder to destination folder while optionally giving it a new name.
     * 
     * @param folderId
     *            - the id of folder to move.
     * @param destinationFolderId
     *            - the id of the destination folder.
     * @param newName
     *            - the new name of moved folder; if <code>newName</code> is
     *            <code>null</code>, the moved folder has same name as the
     *            original.
     * @return The moved folder.
     */
public BoxFolder moveFolder(String folderId, String destinationFolderId, String newName) {
    try {
        LOG.debug("Moving folder(id=" + folderId + ") to destination_folder(id=" + destinationFolderId + ")" + (newName == null ? "" : " with new name '" + newName + "'"));
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (destinationFolderId == null) {
            throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null");
        }
        BoxFolder folderToMove = new BoxFolder(boxConnection, folderId);
        BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId);
        if (newName == null) {
            return (BoxFolder) folderToMove.move(destinationFolder).getResource();
        } else {
            return (BoxFolder) folderToMove.move(destinationFolder, newName).getResource();
        }
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 24 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxFoldersManager method deleteFolder.

/**
     * Delete folder.
     * 
     * @param folderId
     *            - the id of folder to delete.
     */
public void deleteFolder(String folderId) {
    try {
        LOG.debug("Deleting folder(id=" + folderId + ")");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        folder.delete(true);
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 25 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxFoldersManager method getFolderInfo.

/**
     * Get folder information.
     * 
     * @param folderId
     *            - the id of folder.
     * @param fields
     *            - the information fields to retrieve; if <code>null</code> all
     *            information fields are retrieved.
     * @return The folder information.
     */
public BoxFolder.Info getFolderInfo(String folderId, String... fields) {
    try {
        LOG.debug("Getting info for folder(id=" + folderId + ")");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        if (fields == null || fields.length == 0) {
            return folder.getInfo();
        } else {
            return folder.getInfo(fields);
        }
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Aggregations

BoxAPIException (com.box.sdk.BoxAPIException)74 BoxFile (com.box.sdk.BoxFile)24 BoxFolder (com.box.sdk.BoxFolder)17 BoxUser (com.box.sdk.BoxUser)8 BoxTask (com.box.sdk.BoxTask)6 BoxCollaboration (com.box.sdk.BoxCollaboration)4 BoxComment (com.box.sdk.BoxComment)4 BoxGroup (com.box.sdk.BoxGroup)4 BoxFileVersion (com.box.sdk.BoxFileVersion)3 BoxGroupMembership (com.box.sdk.BoxGroupMembership)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)3 IOException (java.io.IOException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Test (org.junit.Test)3 BoxItem (com.box.sdk.BoxItem)2 BoxTaskAssignment (com.box.sdk.BoxTaskAssignment)2 IAccessTokenCache (com.box.sdk.IAccessTokenCache)2