Skip to content

Commit

Permalink
Add implementation to create missing file keys
Browse files Browse the repository at this point in the history
See: #SDKJAVA-35
  • Loading branch information
mkellnhofer committed Feb 20, 2018
1 parent e7245cb commit 5e7c883
Show file tree
Hide file tree
Showing 22 changed files with 429 additions and 86 deletions.
16 changes: 15 additions & 1 deletion example/src/main/java/com/dracoon/sdk/example/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public static void main(String[] args) throws Exception {
//searchNodesPaged(client);

//createDownloadShare(client);
createDownloadShareEncrypted(client);
//createDownloadShareEncrypted(client);

//generateMissingFileKeys(client);
generateMissingFileKeysForOneNode(client);
}

private static void getServerData(DracoonClient client) throws DracoonException {
Expand Down Expand Up @@ -388,4 +391,15 @@ private static void createDownloadShareEncrypted(DracoonClient client) throws Dr
dlShare.getAccessKey()));
}

private static void generateMissingFileKeys(DracoonClient client) throws DracoonException {
client.nodes().generateMissingFileKeys(10);
}

private static void generateMissingFileKeysForOneNode(DracoonClient client)
throws DracoonException {
long nodeId = 1L;

client.nodes().generateMissingFileKeys(nodeId, 10);
}

}
59 changes: 54 additions & 5 deletions src/main/java/com/dracoon/sdk/DracoonClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ void deleteNodes(DeleteNodesRequest request) throws DracoonNetIOException,
* @return the new node
*
* @throws DracoonFileIOException If a file error occurred.
* @throws DracoonCryptoException If a the encryption failed.
* @throws DracoonCryptoException If the encryption failed.
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
*/
Expand All @@ -332,7 +332,7 @@ Node uploadFile(String id, FileUploadRequest request, File file,
* so on. (Null, if not needed.)
*
* @throws DracoonFileIOException If a file error occurred.
* @throws DracoonCryptoException If a the encryption failed.
* @throws DracoonCryptoException If the encryption failed.
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
*/
Expand All @@ -358,7 +358,7 @@ void startUploadFileAsync(String id, FileUploadRequest request, File file,
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
* @throws DracoonCryptoException If a the decryption failed.
* @throws DracoonCryptoException If the decryption failed.
* @throws DracoonFileIOException If a file error occurred.
*/
void downloadFile(String id, long nodeId, File file,
Expand All @@ -376,12 +376,12 @@ void downloadFile(String id, long nodeId, File file,
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
* @throws DracoonCryptoException If the decryption failed.
* @throws DracoonFileIOException If a file error occurred.
* @throws DracoonCryptoException If a the decryption failed.
*/
void startDownloadFileAsync(String id, long nodeId, File file,
FileDownloadCallback callback) throws DracoonNetIOException, DracoonApiException,
DracoonFileIOException, DracoonCryptoException;
DracoonCryptoException, DracoonFileIOException;

/**
* Cancels an asynchronous file download.
Expand Down Expand Up @@ -425,6 +425,55 @@ NodeList searchNodes(long parentNodeId, String searchString)
NodeList searchNodes(long parentNodeId, String searchString, long offset, long limit)
throws DracoonNetIOException, DracoonApiException;

/**
* Generates file keys for files with missing file keys.
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
* @throws DracoonCryptoException If a encryption/decryption failed.
*/
void generateMissingFileKeys() throws DracoonNetIOException, DracoonApiException,
DracoonCryptoException;

/**
* Generates file keys for files with missing file keys. The argument {@code limit}
* restricts the generation to a certain number.
*
* @param limit The number limit. (Number of records; must be positive.)
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
* @throws DracoonCryptoException If a encryption/decryption failed.
*/
void generateMissingFileKeys(int limit) throws DracoonNetIOException, DracoonApiException,
DracoonCryptoException;

/**
* Generates file keys for a file with missing file keys.
*
* @param nodeId The node ID of the file.
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
* @throws DracoonCryptoException If a encryption/decryption failed.
*/
void generateMissingFileKeys(long nodeId) throws DracoonNetIOException, DracoonApiException,
DracoonCryptoException;

/**
* Generates file keys for files with missing file keys. The argument {@code limit}
* restricts the generation to a certain number.
*
* @param nodeId The node ID of the file.
* @param limit The number limit. (Number of records; must be positive.)
*
* @throws DracoonNetIOException If a network error occurred.
* @throws DracoonApiException If the API responded with an error.
* @throws DracoonCryptoException If a encryption/decryption failed.
*/
void generateMissingFileKeys(long nodeId, int limit) throws DracoonNetIOException,
DracoonApiException, DracoonCryptoException;

}

/**
Expand Down
67 changes: 34 additions & 33 deletions src/main/java/com/dracoon/sdk/error/DracoonApiCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,27 @@ public enum DracoonApiCode {
VALIDATION_BAD_FILE_NAME(-135, "Bad file name."),
VALIDATION_EXPIRATION_DATE_IN_PAST(-136, "Expiration date is in past."),
VALIDATION_EXPIRATION_DATE_TOO_LATE(-137, "Expiration date is too late."),
VALIDATION_FILE_KEY_MISSING(-138, "File key has to be provided."),
VALIDATION_FOLDER_FILE_ALREADY_EXISTS(-139, "A folder/file with the same name already exits."),
VALIDATION_ROOM_ALREADY_EXISTS(-140, "A room with the same name already exits."),
VALIDATION_FOLDER_ALREADY_EXISTS(-141, "A folder with the same name already exits."),
VALIDATION_FILE_ALREADY_EXISTS(-142, "A file with the same name already exits."),
VALIDATION_NODES_NOT_IN_SAME_PARENT(-143, "Folders/files must be in same parent."),
VALIDATION_CAN_NOT_MOVE_NODE_TO_OWN_PLACE(-144, "A node can\'t be moved to its own place."),
VALIDATION_ROOM_FOLDER_CAN_NOT_BE_OVERWRITTEN(-145, "A room or folder can\'t be overwritten."),
VALIDATION_FOLDER_CAN_NOT_BE_OVERWRITTEN(-146, "A folder can\'t be overwritten."),
VALIDATION_CAN_NOT_COPY_ROOM(-147, "A rooms can\'t be copied."),
VALIDATION_CAN_NOT_MOVE_ROOM(-148, "A rooms can\'t be moved."),
VALIDATION_PATH_TOO_LONG(-149, "Path is too long."),
VALIDATION_FOLDER_FILE_ALREADY_EXISTS(-138, "A folder/file with the same name already exits."),
VALIDATION_ROOM_ALREADY_EXISTS(-139, "A room with the same name already exits."),
VALIDATION_FOLDER_ALREADY_EXISTS(-140, "A folder with the same name already exits."),
VALIDATION_FILE_ALREADY_EXISTS(-141, "A file with the same name already exits."),
VALIDATION_NODES_NOT_IN_SAME_PARENT(-142, "Folders/files must be in same parent."),
VALIDATION_CAN_NOT_MOVE_NODE_TO_OWN_PLACE(-143, "A node can\'t be moved to its own place."),
VALIDATION_ROOM_FOLDER_CAN_NOT_BE_OVERWRITTEN(-144, "A room or folder can\'t be overwritten."),
VALIDATION_FOLDER_CAN_NOT_BE_OVERWRITTEN(-145, "A folder can\'t be overwritten."),
VALIDATION_CAN_NOT_COPY_ROOM(-146, "A rooms can\'t be copied."),
VALIDATION_CAN_NOT_MOVE_ROOM(-147, "A rooms can\'t be moved."),
VALIDATION_PATH_TOO_LONG(-148, "Path is too long."),
VALIDATION_USER_HAS_NO_KEY_PAIR(-149, "User has no encryption key pair."),
VALIDATION_INVALID_USER_KEY_PAIR(-150, "Invalid encryption key pair."),
VALIDATION_ROOM_NOT_ENCRYPTED(-151, "Room not encrypted."),
VALIDATION_SOURCE_ROOM_NOT_ENCRYPTED(-152, "Encrypted files can\'t be copied or moved to an not encrypted room."),
VALIDATION_TARGET_ROOM_NOT_ENCRYPTED(-153, "Not encrypted files can\'t be copied or moved to an encrypted room."),
VALIDATION_CAN_NOT_CREATE_DL_SHARE_ON_ENCRYPTED_ROOM_FOLDER(-154, "A download share can\'t be created on a encrypted room or folder."),
VALIDATION_PASSWORD_NOT_SECURE(-155, "Password is not secure."),
VALIDATION_EMAIL_ADDRESS_INVALID(-156, "Invalid email address."),
VALIDATION_USER_HAS_NO_FILE_KEY(-151, "User has no encryption file key."),
VALIDATION_USER_FILE_KEY_MISSING(-152, "Encryption file key has to be provided."),
VALIDATION_ROOM_NOT_ENCRYPTED(-153, "Room not encrypted."),
VALIDATION_SOURCE_ROOM_NOT_ENCRYPTED(-154, "Encrypted files can\'t be copied or moved to an not encrypted room."),
VALIDATION_TARGET_ROOM_NOT_ENCRYPTED(-155, "Not encrypted files can\'t be copied or moved to an encrypted room."),
VALIDATION_CAN_NOT_CREATE_DL_SHARE_ON_ENCRYPTED_ROOM_FOLDER(-156, "A download share can\'t be created on a encrypted room or folder."),
VALIDATION_PASSWORD_NOT_SECURE(-157, "Password is not secure."),
VALIDATION_EMAIL_ADDRESS_INVALID(-158, "Invalid email address."),

PERMISSION_ERROR(-160, "User has no permissions to execute the action in this room."),
PERMISSION_MANAGE_ERROR(-161, "User has no permission to manage this room."),
Expand All @@ -69,22 +71,21 @@ public enum DracoonApiCode {
SERVER_TARGET_NODE_NOT_FOUND(-206, "Target room or folder was not found."),
SERVER_TARGET_ROOM_NOT_FOUND(-207, "Target room was not found."),
SERVER_TARGET_FOLDER_NOT_FOUND(-208, "Target folder was not found."),
SERVER_FILE_KEY_NOT_FOUND(-209, "File key could not be found."),
SERVER_UPLOAD_SEGMENT_INVALID(-210, "Provided file segment is invalid."),
SERVER_DOWNLOAD_SEGMENT_INVALID(-211, "Requested file segment is invalid."),
SERVER_INSUFFICIENT_STORAGE(-212, "Not enough free storage on the server."),
SERVER_USER_NOT_FOUND(-213, "User could not be found."),
SERVER_USER_ALREADY_APPROVED_EULA(-214, "User already approved EULA."),
SERVER_USER_CAN_NOT_CHANGE_NAME(-215, "User is not allowed to change his user name."),
SERVER_USER_ALREADY_EXISTS(-216, "A user with this user name already exists."),
SERVER_USER_CAN_NOT_CHANGE_PASSWORD(-217, "User is not allowed to change his password."),
SERVER_USER_CAN_NOT_RESET_PASSWORD(-218, "Password can\'t be reset for this user."),
SERVER_USER_RESET_PASSWORD_EVERY_5_MINUTES(-219, "Password can only be reset every 5 minutes."),
SERVER_UPLOAD_SEGMENT_INVALID(-209, "Provided file segment is invalid."),
SERVER_DOWNLOAD_SEGMENT_INVALID(-210, "Requested file segment is invalid."),
SERVER_INSUFFICIENT_STORAGE(-211, "Not enough free storage on the server."),
SERVER_USER_NOT_FOUND(-212, "User could not be found."),
SERVER_USER_ALREADY_APPROVED_EULA(-213, "User already approved EULA."),
SERVER_USER_CAN_NOT_CHANGE_NAME(-214, "User is not allowed to change his user name."),
SERVER_USER_ALREADY_EXISTS(-215, "A user with this user name already exists."),
SERVER_USER_CAN_NOT_CHANGE_PASSWORD(-216, "User is not allowed to change his password."),
SERVER_USER_CAN_NOT_RESET_PASSWORD(-217, "Password can\'t be reset for this user."),
SERVER_USER_RESET_PASSWORD_EVERY_5_MINUTES(-218, "Password can only be reset every 5 minutes."),
SERVER_USER_KEY_PAIR_NOT_FOUND(-219, "Encryption key pair was not found."),
SERVER_USER_KEY_PAIR_ALREADY_SET(-220, "Encryption key pair was already set."),
SERVER_USER_KEY_PAIR_NOT_FOUND(-221, "Encryption key pair was not found."),
SERVER_USER_HAS_NO_FILE_KEY(-222, "User has no file key for the file."),
SERVER_SMS_IS_DISABLED(-223, "SMS sending is disabled."),
SERVER_SMS_COULD_NOT_BE_SEND(-224, "SMS could not be send.");
SERVER_USER_FILE_KEY_NOT_FOUND(-221, "Encryption file key was not found."),
SERVER_SMS_IS_DISABLED(-222, "SMS sending is disabled."),
SERVER_SMS_COULD_NOT_BE_SEND(-223, "SMS could not be send.");

private final int mNumber;
private final String mText;
Expand Down
Loading

0 comments on commit 5e7c883

Please sign in to comment.