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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations