Package org.sonatype.nexus.configuration.validator

Examples of org.sonatype.nexus.configuration.validator.ApplicationValidationResponse


      if (ctx != null) {
        ctx.incrementGeneration();
      }
    }
    catch (LocalStorageException e) {
      ValidationResponse response = new ApplicationValidationResponse();

      ValidationMessage error =
          new ValidationMessage("overrideLocalStorageUrl", "Repository has an invalid local storage URL '"
              + localUrl, "Invalid file location");

      response.addValidationError(error);

      throw new InvalidConfigurationException(response);
    }

    // clear the NotFoundCache
View Full Code Here


              try {
                proxyRepo.setRemoteUrl(model.getRemoteStorage().getRemoteStorageUrl());
              }
              catch (RemoteStorageException e) {
                ValidationResponse vr = new ApplicationValidationResponse();
                ValidationMessage error = new ValidationMessage("remoteStorageUrl", e.getMessage(), e.getMessage());
                vr.addValidationError(error);
                throw new InvalidConfigurationException(vr);
              }
              String oldPasswordForRemoteStorage = null;
              if (proxyRepo.getRemoteAuthenticationSettings() != null
                  && UsernamePasswordRemoteAuthenticationSettings.class.isInstance(proxyRepo
View Full Code Here

    if (cal.before(nowCal)) {
      if (getLogger().isDebugEnabled()) {
        getLogger().debug("Validation error for startDate: " + startDate.toString());
      }

      ValidationResponse vr = new ApplicationValidationResponse();
      ValidationMessage vm = new ValidationMessage("startDate", "Date cannot be in the past.");
      vr.addValidationError(vm);
      throw new InvalidConfigurationException(vr);
    }
  }
View Full Code Here

  public void validateTime(String key, Date date)
      throws InvalidConfigurationException
  {
    if (date.before(new Date())) {
      ValidationResponse vr = new ApplicationValidationResponse();
      ValidationMessage vm = new ValidationMessage(key, "Time cannot be in the past.");
      vr.addValidationError(vm);
      throw new InvalidConfigurationException(vr);
    }
  }
View Full Code Here

    catch (IncompatibleMasterRepositoryException e) {
      ValidationMessage message =
          new ValidationMessage("shadowOf", e.getMessage(),
              "The source nexus repository is of an invalid Format.");

      ValidationResponse response = new ApplicationValidationResponse();

      response.addValidationError(message);

      throw new InvalidConfigurationException(response);
    }
    catch (NoSuchRepositoryException e) {
      ValidationMessage message =
          new ValidationMessage("shadowOf", e.getMessage(), "The source nexus repository is not existing.");

      ValidationResponse response = new ApplicationValidationResponse();

      response.addValidationError(message);

      throw new InvalidConfigurationException(response);
    }
  }
View Full Code Here

        else {
          prepository.setRemoteStorage(null);
        }
      }
      catch (RemoteStorageException e) {
        ValidationResponse response = new ApplicationValidationResponse();

        ValidationMessage error = new ValidationMessage("remoteStorageUrl", e.getMessage(), e.getMessage());

        response.addValidationError(error);

        throw new InvalidConfigurationException(response);
      }
    }
  }
View Full Code Here

  @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

  @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.nexus.configuration.validator.ApplicationValidationResponse

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.