Search in sources :

Example 11 with BoxAPIException

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

the class BoxTasksManager method getTaskAssignments.

/**
     * Get a list of any assignments for task.
     * 
     * @param taskId
     *            - the id of task.
     * @return The list of assignments for task.
     */
public List<BoxTaskAssignment.Info> getTaskAssignments(String taskId) {
    try {
        LOG.debug("Getting assignments for task(id=" + taskId + ")");
        if (taskId == null) {
            throw new IllegalArgumentException("Parameter 'taskId' can not be null");
        }
        BoxTask file = new BoxTask(boxConnection, taskId);
        return file.getAssignments();
    } 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 : BoxTask(com.box.sdk.BoxTask) BoxAPIException(com.box.sdk.BoxAPIException)

Example 12 with BoxAPIException

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

the class BoxUsersManager method getUserInfo.

/**
     * Get user information.
     * 
     * @param userId
     *            - the id of user.
     * @return The user information.
     */
public BoxUser.Info getUserInfo(String userId) {
    try {
        LOG.debug("Getting info for user(id=" + userId + ")");
        if (userId == null) {
            throw new IllegalArgumentException("Parameter 'userId' can not be null");
        }
        BoxUser user = new BoxUser(boxConnection, userId);
        return user.getInfo();
    } 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) BoxUser(com.box.sdk.BoxUser)

Example 13 with BoxAPIException

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

the class BoxUsersManager method updateUserInfo.

/**
     * Update user information.
     * 
     * @param userId
     *            - the id of user to update.
     * @param info
     *            - the updated information
     * @return The updated user.
     */
public BoxUser updateUserInfo(String userId, BoxUser.Info info) {
    try {
        LOG.debug("Updating info for user(id=" + userId + ")");
        if (userId == null) {
            throw new IllegalArgumentException("Parameter 'userId' can not be null");
        }
        if (info == null) {
            throw new IllegalArgumentException("Parameter 'info' can not be null");
        }
        BoxUser user = new BoxUser(boxConnection, userId);
        user.updateInfo(info);
        return user;
    } 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) BoxUser(com.box.sdk.BoxUser)

Example 14 with BoxAPIException

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

the class BoxConnectionHelper method createAppEnterpriseAuthenticatedConnection.

public static BoxAPIConnection createAppEnterpriseAuthenticatedConnection(BoxConfiguration configuration) {
    // Create Encryption Preferences
    JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
    encryptionPref.setPublicKeyID(configuration.getPublicKeyId());
    try {
        encryptionPref.setPrivateKey(new String(Files.readAllBytes(Paths.get(configuration.getPrivateKeyFile()))));
    } catch (Exception e) {
        throw new RuntimeCamelException("Box API connection failed: could not read privateKeyFile", e);
    }
    encryptionPref.setPrivateKeyPassword(configuration.getPrivateKeyPassword());
    encryptionPref.setEncryptionAlgorithm(configuration.getEncryptionAlgorithm());
    IAccessTokenCache accessTokenCache = configuration.getAccessTokenCache();
    if (accessTokenCache == null) {
        accessTokenCache = new InMemoryLRUAccessTokenCache(configuration.getMaxCacheEntries());
    }
    try {
        return BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(configuration.getEnterpriseId(), configuration.getClientId(), configuration.getClientSecret(), encryptionPref, accessTokenCache);
    } catch (BoxAPIException e) {
        throw new RuntimeCamelException(String.format("Box API connection failed: API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : JWTEncryptionPreferences(com.box.sdk.JWTEncryptionPreferences) InMemoryLRUAccessTokenCache(com.box.sdk.InMemoryLRUAccessTokenCache) IAccessTokenCache(com.box.sdk.IAccessTokenCache) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoxAPIException(com.box.sdk.BoxAPIException) BoxAPIException(com.box.sdk.BoxAPIException) GeneralSecurityException(java.security.GeneralSecurityException) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

Example 15 with BoxAPIException

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

the class BoxConnectionHelper method createAppUserAuthenticatedConnection.

public static BoxAPIConnection createAppUserAuthenticatedConnection(BoxConfiguration configuration) {
    // Create Encryption Preferences
    JWTEncryptionPreferences encryptionPref = new JWTEncryptionPreferences();
    encryptionPref.setPublicKeyID(configuration.getPublicKeyId());
    try {
        encryptionPref.setPrivateKey(new String(Files.readAllBytes(Paths.get(configuration.getPrivateKeyFile()))));
    } catch (Exception e) {
        throw new RuntimeCamelException("Box API connection failed: could not read privateKeyFile", e);
    }
    encryptionPref.setPrivateKeyPassword(configuration.getPrivateKeyPassword());
    encryptionPref.setEncryptionAlgorithm(configuration.getEncryptionAlgorithm());
    IAccessTokenCache accessTokenCache = configuration.getAccessTokenCache();
    if (accessTokenCache == null) {
        accessTokenCache = new InMemoryLRUAccessTokenCache(configuration.getMaxCacheEntries());
    }
    try {
        return BoxDeveloperEditionAPIConnection.getAppUserConnection(configuration.getUserId(), configuration.getClientId(), configuration.getClientSecret(), encryptionPref, accessTokenCache);
    } catch (BoxAPIException e) {
        throw new RuntimeCamelException(String.format("Box API connection failed: API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : JWTEncryptionPreferences(com.box.sdk.JWTEncryptionPreferences) InMemoryLRUAccessTokenCache(com.box.sdk.InMemoryLRUAccessTokenCache) IAccessTokenCache(com.box.sdk.IAccessTokenCache) RuntimeCamelException(org.apache.camel.RuntimeCamelException) BoxAPIException(com.box.sdk.BoxAPIException) BoxAPIException(com.box.sdk.BoxAPIException) GeneralSecurityException(java.security.GeneralSecurityException) FailingHttpStatusCodeException(com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException) RuntimeCamelException(org.apache.camel.RuntimeCamelException) IOException(java.io.IOException)

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