Package org.sonatype.configuration.validation

Examples of org.sonatype.configuration.validation.ValidationResponse


      this.eventBus.post(new SecurityConfigurationChanged());
    }

    upgradeNexusVersion();

    ValidationResponse vResponse =
        getConfigurationValidator().validateModel(new ValidationRequest(getConfiguration()));

    dumpValidationErrors(vResponse);

    setValidationResponse(vResponse);

    if (vResponse.isValid()) {
      if (vResponse.isModified()) {
        log.info("Validation has modified the configuration, storing the changes.");

        storeConfiguration();
      }
View Full Code Here


    return response;
  }

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

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

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

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

    if (StringUtils.isEmpty(settings.getName())) {
      response.addValidationError("The RepositoryTarget may have no empty/null Name!");
    }

    if (StringUtils.isEmpty(settings.getContentClass())) {
      response.addValidationError("Repository target with ID='" + settings.getId()
          + "' has empty content class!");
    }

    if (context.getExistingRepositoryTargetIds() != null) {
      // check for uniqueness
      for (String id : context.getExistingRepositoryTargetIds()) {
        if (id.equals(settings.getId())) {
          response.addValidationError("This target ID is already existing!");
        }
      }
    }

    List<String> patterns = settings.getPatterns();

    if (patterns != null && patterns.size() > 0) {
      for (String pattern : patterns) {
        if (!isValidRegexp(pattern)) {
          response.addValidationError("Repository target with ID='" + settings.getId()
              + "' has invalid regexp pattern: " + pattern);
        }
      }
    }
    else {
      response.addValidationError("Repository target with ID='" + settings.getId()
          + "' has no regexp pattern defined!");
    }

    return response;
  }
View Full Code Here

    return response;
  }

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

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

    return response;
  }
View Full Code Here

    return response;
  }

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

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

    return response;
  }
View Full Code Here

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

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

    return response;
  }
View Full Code Here

    return response;
  }

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

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

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

    response.append(validateSchedule(context, settings.getSchedule()));

    return response;
  }
View Full Code Here

    return response;
  }

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

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

    return response;
  }
View Full Code Here

    return response;
  }

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

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

    if (StringUtils.isEmpty(settings.getHostname())) {
      ValidationMessage msg = new ValidationMessage("host", "SMTP Host is empty.");
      response.addValidationError(msg);
    }

    if (settings.getPort() < 0) {
      ValidationMessage msg = new ValidationMessage(
          "port",
          "SMTP Port is inavlid.  Enter a port greater than 0.");
      response.addValidationError(msg);
    }

    if (StringUtils.isEmpty(settings.getSystemEmailAddress())) {
      ValidationMessage msg = new ValidationMessage("systemEmailAddress", "System Email Address is empty.");
      response.addValidationError(msg);
    }

    return response;
  }
View Full Code Here

  @Override
  public ValidationResponse doValidateChanges(CRepositoryGrouping changedConfiguration) {
    CRepositoryGrouping settings = (CRepositoryGrouping) changedConfiguration;

    ValidationResponse response = new ApplicationValidationResponse();

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

    context.addExistingPathMappingIds();

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

    return response;
  }
View Full Code Here

  }

  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 : (List<String>) 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 + "'.");
    }

    if (!CPathMappingItem.BLOCKING_RULE_TYPE.equals(item.getRouteType())) {
      // NOT TRUE ANYMORE:
      // 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

      // here we must have a repo list
      // if ( item.getRepositories() == null || item.getRepositories().size() == 0 )
      // {
      // response.addValidationError( "The repository list in Route with ID='" + item.getId()
      // + "' is not valid: it cannot be empty!" );
      // }
    }

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

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

      for (String repoId : (List<String>) 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

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.