Search in sources :

Example 36 with BoxAPIException

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

the class BoxCollaborationsManager method addFolderCollaboration.

/**
     * Add a collaboration to this folder.
     * 
     * @param folderId
     *            - the id of folder to add collaboration to.
     * @param collaborator
     *            - the collaborator to add.
     * @param role
     *            - the role of the collaborator.
     * 
     * @return The new collaboration.
     */
// compiler for some reason thinks 'if
@SuppressWarnings("unused")
public // (collaborator == null)' clause is dead code.
BoxCollaboration addFolderCollaboration(String folderId, BoxCollaborator collaborator, BoxCollaboration.Role role) {
    try {
        LOG.debug("Creating  collaborations for folder(id=" + folderId + ") with collaborator(" + collaborator.getID() + ")");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (collaborator == null) {
            throw new IllegalArgumentException("Parameter 'collaborator' can not be null");
        }
        if (role == null) {
            throw new IllegalArgumentException("Parameter 'role' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        return folder.collaborate(collaborator, role).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 37 with BoxAPIException

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

the class BoxCollaborationsManager method deleteCollaboration.

/**
     * Delete collaboration.
     * 
     * @param collaborationId
     *            - the id of comment to change.
     * @return The comment with changed message.
     */
public void deleteCollaboration(String collaborationId) {
    try {
        LOG.debug("Deleting collaboration(id=" + collaborationId + ")");
        if (collaborationId == null) {
            throw new IllegalArgumentException("Parameter 'collaborationId' can not be null");
        }
        BoxCollaboration collaboration = new BoxCollaboration(boxConnection, collaborationId);
        collaboration.delete();
    } 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) BoxCollaboration(com.box.sdk.BoxCollaboration)

Example 38 with BoxAPIException

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

the class BoxCollaborationsManager method addFolderCollaborationByEmail.

/**
     * Add a collaboration to this folder. An email will be sent to the
     * collaborator if they don't already have a Box account.
     * 
     * @param folderId
     *            - the id of folder to add collaboration to.
     * @param email
     *            - the email address of the collaborator to add.
     * @param role
     *            - the role of the collaborator.
     * 
     * @return The new collaboration.
     */
public BoxCollaboration addFolderCollaborationByEmail(String folderId, String email, BoxCollaboration.Role role) {
    try {
        LOG.debug("Creating  collaborations for folder(id=" + folderId + ") with collaborator(" + email + ")");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (email == null) {
            throw new IllegalArgumentException("Parameter 'email' can not be null");
        }
        if (role == null) {
            throw new IllegalArgumentException("Parameter 'role' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        return folder.collaborate(email, role).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 39 with BoxAPIException

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

the class BoxFilesManager method getFilePreviewLink.

/**
     * Get an expiring URL for creating an embedded preview session. The URL
     * will expire after 60 seconds and the preview session will expire after 60
     * minutes.
     * 
     * @param fileId
     *            - the id of the file to get preview link on.
     * @return The preview link.
     */
public URL getFilePreviewLink(String fileId) {
    try {
        LOG.debug("Getting preview link for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        return file.getPreviewLink();
    } 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 : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException)

Example 40 with BoxAPIException

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

the class BoxFilesManager method getFileMetadata.

/**
     * Gets the file properties metadata.
     * 
     * @param fileId
     *            - the id of the file to retrieve metadata for.
     * @param typeName
     *            - the metadata template type name; if <code>null</code> the
     *            global properties template type is used.
     * @return The metadata returned from the server.
     */
public Metadata getFileMetadata(String fileId, String typeName) {
    try {
        LOG.debug("Get metadata for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        if (typeName != null) {
            return file.getMetadata(typeName);
        } else {
            return file.getMetadata();
        }
    } 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 : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException)

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