@Override public ValidationResult validate(RuntimeContainer container) { ValidationResult vr = new ValidationResultMutable(Result.OK); // check for Connection attributes if (StringUtils.isEmpty(serviceAccountFile)) { vr = new ValidationResultMutable(Result.ERROR).setMessage("Service Account JSON File cannot be empty."); return vr; } try { // make a dummy call to check drive's connection.. User u = getDriveService().about().get().setFields("user").execute().getUser(); LOG.debug("[validate] Testing User Properties: {}.", u); } catch (Exception ex) { LOG.error("[validate] {}.", ex.getMessage()); vr = new ValidationResultMutable(Result.ERROR).setMessage(ex.getMessage()); return vr; } return ValidationResult.OK; }
@Override public ValidationResult validate(RuntimeContainer container) { ValidationResult vr = new ValidationResultMutable(Result.OK); // check for Connection attributes if (StringUtils.isEmpty(serviceAccountFile)) { vr = new ValidationResultMutable(Result.ERROR).setMessage("Service Account JSON File cannot be empty."); return vr; } try { // make a dummy call to check drive's connection.. User u = getDriveService().about().get().setFields("user").execute().getUser(); LOG.debug("[validate] Testing User Properties: {}.", u); } catch (Exception ex) { LOG.error("[validate] {}.", ex.getMessage()); vr = new ValidationResultMutable(Result.ERROR).setMessage(ex.getMessage()); return vr; } return ValidationResult.OK; }
/** * Gets information about the user, the user's Drive, and system capabilities. * * Create a request for the method "about.get". * * This request holds the parameters needed by the drive server. After setting any optional * parameters, call the {@link Get#execute()} method to invoke the remote operation. * * @return the request */ public Get get() throws java.io.IOException { Get result = new Get(); initialize(result); return result; }
@Override public Space get() throws BackgroundException { try { final About about = session.getClient().about().get().setFields("user, storageQuota").execute(); final Long used = null == about.getStorageQuota().getUsage() ? 0L : about.getStorageQuota().getUsage(); final Long available = null == about.getStorageQuota().getLimit() ? Long.MAX_VALUE : about.getStorageQuota().getLimit() - used; return new Space(used, available); } catch(IOException e) { throw new DriveExceptionMappingService().map("Failure to read attributes of {0}", e, new Path(String.valueOf(Path.DELIMITER), EnumSet.of(Path.Type.volume, Path.Type.directory))); } } }