Package org.sonatype.configuration.validation

Examples of org.sonatype.configuration.validation.ValidationResponse


  @Override
  public ValidationResponse doValidateChanges(CRepository changedConfiguration) {
    CRepository cfg = (CRepository) changedConfiguration;

    ValidationResponse response = new ApplicationValidationResponse();

    // ID
    if (StringUtils.isBlank(cfg.getId())) {
      response.addValidationError(new ValidationMessage("id", "Repository ID must not be blank!"));
    }
    else if (!cfg.getId().matches(REPOSITORY_ID_PATTERN)) {
      response.addValidationError(new ValidationMessage("id",
          "Only letters, digits, underscores, hyphens, and dots are allowed in Repository ID"));
    }

    // ID not 'all'
    if ("all".equals(cfg.getId())) {
      response.addValidationError(new ValidationMessage("id", "Repository ID can't be 'all', reserved word"));
    }

    // Name
    if (StringUtils.isBlank(cfg.getName())) {
      response.addValidationWarning(new ValidationMessage("id", "Repository with ID='" + cfg.getId()
          + "' has no name, defaulted it's name to it's ID."));

      cfg.setName(cfg.getId());

      response.setModified(true);
    }

    // LocalStatus
    try {
      LocalStatus.valueOf(cfg.getLocalStatus());
    }
    catch (Exception e) {
      response.addValidationError(new ValidationMessage("localStatus", "LocalStatus of repository with ID=\""
          + cfg.getId() + "\" has unacceptable value \"" + cfg.getLocalStatus() + "\"! (Allowed values are: \""
          + LocalStatus.IN_SERVICE + "\" and \"" + LocalStatus.OUT_OF_SERVICE + "\")", e));
    }

    // indexable
    if (cfg.isIndexable() && (!"maven2".equals(cfg.getProviderHint()))) {
      response.addValidationWarning(new ValidationMessage("indexable", "Indexing isn't supported for \""
          + cfg.getProviderHint() + "\" repositories, only Maven2 repositories are indexable!"));

      cfg.setIndexable(false);

      response.setModified(true);
    }

    // proxy repo URL (if set) -- it must end with a slash (true for Maven1/2 reposes!)
    // TODO: This is temporary solution until we cleanup config framework.
    // This check below should happen in _maven specific_ configuration validation, not here in core
View Full Code Here


    return response;
  }

  @Override
  public ValidationResponse validateRepositoryGrouping(ApplicationValidationContext ctx, CRepositoryGrouping settings) {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    ApplicationValidationContext context = (ApplicationValidationContext) response.getContext();

    context.addExistingPathMappingIds();

    if (settings.getPathMappings() != null) {
      for (CPathMappingItem item : settings.getPathMappings()) {
        response.append(validateGroupsSettingPathMappingItem(context, item));
      }
    }

    return response;
  }
View Full Code Here

  @Override
  public ValidationResponse validateGroupsSettingPathMappingItem(ApplicationValidationContext ctx,
                                                                 CPathMappingItem item)
  {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    ApplicationValidationContext context = (ApplicationValidationContext) response.getContext();

    if (StringUtils.isEmpty(item.getId())
        || "0".equals(item.getId())
        || (context.getExistingPathMappingIds() != null && context.getExistingPathMappingIds().contains(
        item.getId()))) {
      String newId = generateId();

      item.setId(newId);

      response.addValidationWarning("Fixed wrong route ID from '" + item.getId() + "' to '" + newId + "'");

      response.setModified(true);
    }

    if (StringUtils.isEmpty(item.getGroupId())) {
      item.setGroupId(CPathMappingItem.ALL_GROUPS);

      response
          .addValidationWarning("Fixed route without groupId set, set to ALL_GROUPS to keep backward comp, ID='"
              + item.getId() + "'.");

      response.setModified(true);
    }

    if (item.getRoutePatterns() == null || item.getRoutePatterns().isEmpty()) {
      response.addValidationError("The Route with ID='" + item.getId() + "' must contain at least one Route Pattern.");
    }

    for (String regexp : item.getRoutePatterns()) {
      if (!isValidRegexp(regexp)) {
        response.addValidationError("The regexp in Route with ID='" + item.getId() + "' is not valid: "
            + regexp);
      }
    }

    if (context.getExistingPathMappingIds() != null) {
      context.getExistingPathMappingIds().add(item.getId());
    }

    if (!CPathMappingItem.INCLUSION_RULE_TYPE.equals(item.getRouteType())
        && !CPathMappingItem.EXCLUSION_RULE_TYPE.equals(item.getRouteType())
        && !CPathMappingItem.BLOCKING_RULE_TYPE.equals(item.getRouteType())) {
      response.addValidationError("The groupMapping pattern with ID=" + item.getId()
          + " have invalid routeType='" + item.getRouteType() + "'. Valid route types are '"
          + CPathMappingItem.INCLUSION_RULE_TYPE + "', '" + CPathMappingItem.EXCLUSION_RULE_TYPE + "' and '"
          + CPathMappingItem.BLOCKING_RULE_TYPE + "'.");
    }

    // REMOVED: check that a blocking route is not empty
    // if you delete a repo(ses) that were belonging to a route, we insist on
    // leaving the route "empty" (to save a users hardly concieved regexp) but with empty
    // repo list

    if (context.getExistingRepositoryIds() != null && context.getExistingRepositoryShadowIds() != null) {
      List<String> existingReposes = context.getExistingRepositoryIds();

      List<String> existingShadows = context.getExistingRepositoryShadowIds();

      for (String repoId : item.getRepositories()) {
        if (!existingReposes.contains(repoId) && !existingShadows.contains(repoId)) {
          response.addValidationError("The groupMapping pattern with ID=" + item.getId()
              + " refers to a nonexistent repository with repoID = " + repoId);
        }
      }
    }
View Full Code Here

    if (applyConfiguration()) {
      // TODO: when NEXUS-2215 is fixed, this should be remove/moved/cleaned
      // START <<<
      // validate before we do anything
      ValidationRequest request = new ValidationRequest(configurationSource.getConfiguration());
      ValidationResponse response = configurationValidator.validateModel(request);
      if (!response.isValid()) {
        this.log.error("Saving nexus configuration caused unexpected error:\n" + response.toString());
        throw new IOException("Saving nexus configuration caused unexpected error:\n" + response.toString());
      }
      // END <<<

      configurationSource.storeConfiguration();
View Full Code Here

    return response;
  }

  @Override
  public ValidationResponse validateHttpProxySettings(ApplicationValidationContext ctx, CHttpProxySettings settings) {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    if (settings.getPort() < 80) {
      settings.setPort(8082);

      response.addValidationWarning("The HTTP Proxy port is below 80? Settings defaulted.");

      response.setModified(true);
    }

    if (!CHttpProxySettings.PROXY_POLICY_PASS_THRU.equals(settings.getProxyPolicy())
        && !CHttpProxySettings.PROXY_POLICY_STRICT.equals(settings.getProxyPolicy())) {
      response.addValidationError("The HTTP Proxy policy settings is invalid: '" + settings.getProxyPolicy()
          + "'. Valid policies are '" + CHttpProxySettings.PROXY_POLICY_STRICT + "' and '"
          + CHttpProxySettings.PROXY_POLICY_PASS_THRU + "'.");
    }

    return response;
View Full Code Here

    if (!create && !Strings.isNullOrEmpty(settings.getId())) {
      // remove "itself" from the list to avoid hitting "duplicate repo" problem
      ctx.getExistingRepositoryIds().remove(settings.getId());
    }

    ValidationResponse vr = configurationValidator.validateRepository(ctx, settings);

    if (!vr.isValid()) {
      throw new InvalidConfigurationException(vr);
    }
  }
View Full Code Here

  @Override
  public ValidationResponse validateRemoteAuthentication(ApplicationValidationContext ctx,
                                                         CRemoteAuthentication settings)
  {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    return response;
  }
View Full Code Here

  @Override
  public ValidationResponse validateRemoteConnectionSettings(ApplicationValidationContext ctx,
                                                             CRemoteConnectionSettings settings)
  {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    return response;
  }
View Full Code Here

  @Override
  public ValidationResponse validateRemoteHttpProxySettings(ApplicationValidationContext ctx,
                                                            CRemoteHttpProxySettings settings)
  {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    if (settings.getProxyPort() < 1 || settings.getProxyPort() > 65535) {
      response.addValidationError("The proxy port must be an integer between 1 and 65535!");
    }

    response.append(validateRemoteAuthentication(ctx, settings.getAuthentication()));

    return response;
  }
View Full Code Here

    return response;
  }

  @Override
  public ValidationResponse validateRepositoryMirrors(ApplicationValidationContext ctx, List<CMirror> mirrors) {
    ValidationResponse response = new ApplicationValidationResponse();

    if (ctx != null) {
      response.setContext(ctx);
    }

    for (CMirror mirror : mirrors) {
      if (StringUtils.isEmpty(mirror.getId())) {
        String newId = generateId();

        mirror.setId(newId);

        response
            .addValidationWarning("Fixed wrong mirror ID from '" + mirror.getId() + "' to '" + newId + "'");

        response.setModified(true);
      }

      if (StringUtils.isEmpty(mirror.getId())) {
        response.addValidationError("The Mirror may have no empty/null ID!");
      }

      if (StringUtils.isEmpty(mirror.getUrl())) {
        response.addValidationError("The Mirror may have no empty/null URL!");
      }
    }

    return response;
  }
View Full Code Here

TOP

Related Classes of org.sonatype.configuration.validation.ValidationResponse

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.