Search in sources :

Example 1 with FolderRequest

use of org.syncany.operations.daemon.messages.api.FolderRequest in project syncany by syncany.

the class CommandLineClient method buildFolderRequestFromCommand.

private Request buildFolderRequestFromCommand(Command command, String commandName, String[] commandArgs, String root) throws Exception {
    // TODO [low] Medium-dirty hack.
    String thisPackage = BadRequestResponse.class.getPackage().getName();
    String camelCaseMessageType = StringUtil.toCamelCase(commandName) + FolderRequest.class.getSimpleName();
    String fqMessageClassName = thisPackage + "." + camelCaseMessageType;
    FolderRequest folderRequest;
    try {
        Class<? extends FolderRequest> folderRequestClass = Class.forName(fqMessageClassName).asSubclass(FolderRequest.class);
        folderRequest = folderRequestClass.newInstance();
    } catch (Exception e) {
        logger.log(Level.INFO, "Could not find FQCN " + fqMessageClassName, e);
        throw new Exception("Cannot read request class from request type: " + commandName, e);
    }
    OperationOptions operationOptions = command.parseOptions(commandArgs);
    int requestId = Math.abs(new Random().nextInt());
    folderRequest.setRoot(root);
    folderRequest.setId(requestId);
    folderRequest.setOptions(operationOptions);
    return folderRequest;
}
Also used : OperationOptions(org.syncany.operations.OperationOptions) FolderRequest(org.syncany.operations.daemon.messages.api.FolderRequest) BadRequestResponse(org.syncany.operations.daemon.messages.BadRequestResponse) Random(java.util.Random) ConfigException(org.syncany.config.ConfigException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 Random (java.util.Random)1 ConfigException (org.syncany.config.ConfigException)1 OperationOptions (org.syncany.operations.OperationOptions)1 BadRequestResponse (org.syncany.operations.daemon.messages.BadRequestResponse)1 FolderRequest (org.syncany.operations.daemon.messages.api.FolderRequest)1