Package com.google.api.ads.common.lib.exception

Examples of com.google.api.ads.common.lib.exception.ValidationException


     */
    private void validate() throws ValidationException {
      // Check for at least one authentication mechanism.
      if (this.clientLoginToken == null
          && this.oAuth2Credential == null) {
        throw new ValidationException(
            "Either ClientLogin or OAuth2 authentication must be used.", "");
      }

      // Check that application name is not empty or the default.
      if (Strings.isNullOrEmpty(applicationName)
          || applicationName.contains(DEFAULT_APPLICATION_NAME)) {
        throw new ValidationException(String.format(
            "Application name must be set and not be the default [%s]", DEFAULT_APPLICATION_NAME),
            "applicationName");
      }


      // Make sure they specify a valid endpoint.
      try {
        new URL(this.endpoint);
      } catch (MalformedURLException e) {
        throw new ValidationException(String.format("Endpoint [%s] not recognized as a valid URL.",
            this.endpoint), "endpoint", e);
      }
    }
View Full Code Here


     */
    private void validate() throws ValidationException {
      // Check for at least one authentication mechanism.
      if (this.clientLoginToken == null
          && this.oAuth2Credential == null) {
        throw new ValidationException(
            "ClientLogin or OAuth2 authentication must be used.", "");
      }

      // Check that the developer token is set.
      if (this.developerToken == null) {
        throw new ValidationException("A developer token must be set.", "developerToken");
      }
     
      // Check that user agent is not empty or the default.
      if (Strings.isNullOrEmpty(userAgent)
          || userAgent.contains(DEFAULT_USER_AGENT)) {
        throw new ValidationException(String.format(
            "User agent must be set and not be the default [%s]", DEFAULT_USER_AGENT),
            "userAgent");
      }

      // Make sure they specify an endpoint.
      try {
        new URL(this.endpoint);
      } catch (MalformedURLException e) {
        throw new ValidationException(String.format("Endpoint [%s] not recognized as a valid URL.",
            this.endpoint), "endpoint", e);
      }
    }
View Full Code Here

    private void validate() throws ValidationException {
      if (environmentString != null) {
        try {
          withEnvironment(Environment.valueOf(environmentString.toUpperCase()));
        } catch (IllegalArgumentException e) {
          throw new ValidationException(String.format("Environment [%s] not recognized.",
              environmentString), "api.dfa.environment", e);
        }
      }

      // Check for valid username.
      if (this.username == null) {
        throw new ValidationException("Username is required.", "username");
      }

      boolean usingPassword = this.password != null;
      boolean usingToken = this.authenticationToken != null;
      boolean usingOAuth2 = this.oAuth2Credential != null;

      // Check that at least one auth mechanism is being use.
      if (!usingPassword && !usingToken && !usingOAuth2) {
        throw new ValidationException(
            "One of username/password, username/token or username/OAuth2 must be used.",
            "");
      }

      // Check that only one auth mechanism is being used.
      if ((usingPassword && usingToken) || (usingPassword && usingOAuth2) ||
          (usingToken && usingOAuth2)) {
        throw new ValidationException(
            "You may only use one of username/password, username/token, and username/OAuth2 at " +
            "the same time.",
            "");
      }

      // Check that application name is not empty or the default.
      if (Strings.isNullOrEmpty(applicationName)
          || applicationName.contains(DEFAULT_APPLICATION_NAME)) {
        throw new ValidationException(String.format(
            "Application name must be set and not be the default [%s]", DEFAULT_APPLICATION_NAME),
            "applicationName");
      }

      // Make sure they specify an environment.
      try {
        new URL(this.endpoint);
      } catch (MalformedURLException e) {
        throw new ValidationException("Endpoint is required and must be a valid URL.",
            "endpoint", e);
      }
    }
View Full Code Here

     * @throws ValidationException if the {@code GoogleClientSecrets} did not
     *          validate
     */
    private void validate() throws ValidationException {
      if (Strings.isNullOrEmpty(clientId)) {
        throw new ValidationException(String.format(
            "Client ID must be set%s\nIf you do not have a client ID or secret, "
            + "please create one in the API console: https://code.google.com/apis/console#access",
            filePath != null ? generateFilePathWarning("clientId") : "."), "clientId");
      }

      if (Strings.isNullOrEmpty(clientSecret)) {
        throw new ValidationException(String.format(
            "Client secret must be set%s\nIf you do not have a client ID or secret, "
            + "please create one in the API console: https://code.google.com/apis/console#access",
            filePath != null ? generateFilePathWarning("clientSecret") : "."),
            "clientSecret");
      }
View Full Code Here

     * @throws ValidationException if the {@code OfflineCredentials} did not
     *          validate
     */
    private void validate() throws ValidationException {
      if (Strings.isNullOrEmpty(this.clientId)) {
        throw new ValidationException(String.format("Client ID must be set%s\n"
            + "If you do not have a client ID or secret, please create one in the API console: "
            + "https://code.google.com/apis/console#access",
            this.filePath != null ? generateFilePathWarning("clientId") : "."),
            "clientId");
      }

      if (Strings.isNullOrEmpty(this.clientSecret)) {
        throw new ValidationException(String.format("Client secret must be set%s\n"
            + "If you do not have a client ID or secret, please create one in the API console: "
            + "https://code.google.com/apis/console#access",
            this.filePath != null ? generateFilePathWarning("clientSecret") : "."),
            "clientSecret");
      }

      if (Strings.isNullOrEmpty(this.refreshToken)) {
        throw new ValidationException(String.format("A refresh token must be set%s\n"
            + "It is required for offline credentials. If you need to create one, see the "
            + "GetRefreshToken example.",
            this.filePath != null ? generateFilePathWarning("refreshToken") : "."),
            "refreshToken");
      }
View Full Code Here

     */
    private void validate() throws ValidationException {
      if (!Strings.isNullOrEmpty(clientLoginTokens.clientLoginTokenOverride)
          && (!Strings.isNullOrEmpty(clientLoginTokens.clientLogin.getUsername())
              || !Strings.isNullOrEmpty(clientLoginTokens.clientLogin.getPassword()))) {
        throw new ValidationException(
            "Email and password or client login token should be set. Not both.", "");
      }

      if (Strings.isNullOrEmpty(clientLoginTokens.clientLoginTokenOverride)
          && (Strings.isNullOrEmpty(clientLoginTokens.clientLogin.getUsername())
              || Strings.isNullOrEmpty(clientLoginTokens.clientLogin.getPassword()))) {
        throw new ValidationException(
            "Email and password or client login token must be set.", "");
      }
    }
View Full Code Here

TOP

Related Classes of com.google.api.ads.common.lib.exception.ValidationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.