// clean
  protected RepositoryListResourceResponse listRepositories(
      Request request, boolean allReposes, boolean includeGroups) throws ResourceException {
    RepositoryListResourceResponse result = new RepositoryListResourceResponse();

    RepositoryListResource repoRes;

    Collection<Repository> repositories = getRepositoryRegistry().getRepositories();

    for (Repository repository : repositories) {
      // To save UI changes at the moment, not including groups in repo call
      if ((allReposes || repository.isUserManaged())
          && (includeGroups
              || !repository.getRepositoryKind().isFacetAvailable(GroupRepository.class))) {
        repoRes = new RepositoryListResource();

        repoRes.setResourceURI(createRepositoryReference(request, repository.getId()).toString());

        repoRes.setContentResourceURI(
            repositoryURLBuilder.getExposedRepositoryContentUrl(repository));

        repoRes.setRepoType(getRestRepoType(repository));

        repoRes.setProvider(NexusCompat.getRepositoryProviderHint(repository));

        repoRes.setProviderRole(NexusCompat.getRepositoryProviderRole(repository));

        repoRes.setFormat(repository.getRepositoryContentClass().getId());

        repoRes.setId(repository.getId());

        repoRes.setName(repository.getName());

        repoRes.setUserManaged(repository.isUserManaged());

        repoRes.setExposed(repository.isExposed());

        repoRes.setEffectiveLocalStorageUrl(repository.getLocalUrl());

        if (repository.getRepositoryKind().isFacetAvailable(MavenRepository.class)) {
          repoRes.setRepoPolicy(
              repository.adaptToFacet(MavenRepository.class).getRepositoryPolicy().toString());
        }

        if (repository.getRepositoryKind().isFacetAvailable(ProxyRepository.class)) {
          repoRes.setRemoteUri(repository.adaptToFacet(ProxyRepository.class).getRemoteUrl());
        }

        result.addData(repoRes);
      }
    }

    return result;
  }
 protected void setDefaults() throws MalformedURLException, URISyntaxException {
   final Repository repository = findRepository();
   if (isBlank(getRpmDir()) && repository != null) {
     setRpmDir(RepositoryUtils.getBaseDir(repository).getAbsolutePath());
   }
   if (isBlank(getRpmUrl()) && repository != null) {
     final String rpmUrl = repositoryURLBuilder.getExposedRepositoryContentUrl(repository, true);
     if (StringUtils.isBlank(rpmUrl)) {
       throw new IllegalStateException(
           SimpleFormat.format(
               "Not able to build content URL of the repository \"%s\" [id=%s], baseUrl not set!",
               repository.getName(), repository.getId()));
     }
     setRpmUrl(rpmUrl);
   }
   if (isBlank(getParameter(PARAM_REPO_DIR)) && isNotBlank(getRpmDir())) {
     setRepoDir(new File(getRpmDir()));
   }
   if (isBlank(getRepoUrl()) && isNotBlank(getRpmUrl())) {
     setRepoUrl(getRpmUrl());
   }
 }
  public RepositoryShadowResource getRepositoryShadowRestModel(
      Request request, ShadowRepository shadow) {
    RepositoryShadowResource resource = new RepositoryShadowResource();

    resource.setId(shadow.getId());

    resource.setName(shadow.getName());

    resource.setContentResourceURI(repositoryURLBuilder.getExposedRepositoryContentUrl(shadow));

    resource.setProvider(NexusCompat.getRepositoryProviderHint(shadow));

    resource.setRepoType(RepositoryBaseResourceConverter.REPO_TYPE_VIRTUAL);

    resource.setFormat(shadow.getRepositoryContentClass().getId());

    resource.setShadowOf(shadow.getMasterRepository().getId());

    resource.setSyncAtStartup(shadow.isSynchronizeAtStartup());

    resource.setExposed(shadow.isExposed());

    return resource;
  }
  /** Converting App model to REST DTO. */
  public RepositoryBaseResource getRepositoryRestModel(Request request, Repository repository) {
    RepositoryResource resource = null;

    if (repository.getRepositoryKind().isFacetAvailable(ProxyRepository.class)) {
      resource = getRepositoryProxyRestModel(repository.adaptToFacet(ProxyRepository.class));
    } else if (repository.getRepositoryKind().isFacetAvailable(ShadowRepository.class)) {
      return getRepositoryShadowRestModel(request, repository.adaptToFacet(ShadowRepository.class));
    } else {
      resource = new RepositoryResource();
    }

    resource.setContentResourceURI(repositoryURLBuilder.getExposedRepositoryContentUrl(repository));

    resource.setProvider(NexusCompat.getRepositoryProviderHint(repository));

    resource.setProviderRole(NexusCompat.getRepositoryProviderRole(repository));

    resource.setFormat(repository.getRepositoryContentClass().getId());

    resource.setRepoType(getRestRepoType(repository));

    resource.setId(repository.getId());

    resource.setName(repository.getName());

    resource.setWritePolicy(repository.getWritePolicy().name());

    resource.setBrowseable(repository.isBrowseable());

    resource.setIndexable(repository.isSearchable());

    resource.setExposed(repository.isExposed());

    resource.setNotFoundCacheTTL(repository.getNotFoundCacheTimeToLive());

    // TODO: remove the default local storage, this is a work around for NEXUS-1994
    // the new 1.4 API doesn't store the default URL, well, it is part of the CRepo, but it is not
    // exposed.
    // so we can figure it out again, I think the default local Storage should be removed from the
    // REST message
    // which is part of the reason for not exposing it. The other part is it is not used anywhere
    // except to set
    // the localUrl if not already set.

    // apples to apples here, man i hate this section of code!!!!
    // always set to default (see AbstractRepositoryConfigurator)
    String defaultLocalStorageUrl =
        ((CRepositoryCoreConfiguration) repository.getCurrentCoreConfiguration())
            .getConfiguration(false)
            .defaultLocalStorageUrl;
    resource.setDefaultLocalStorageUrl(defaultLocalStorageUrl);

    // if not user set (but using default), this is null, otherwise it contains user-set value
    String overrideLocalStorageUrl =
        ((CRepositoryCoreConfiguration) repository.getCurrentCoreConfiguration())
            .getConfiguration(false)
            .getLocalStorage()
            .getUrl();
    if (StringUtils.isNotBlank(overrideLocalStorageUrl)) {
      resource.setOverrideLocalStorageUrl(overrideLocalStorageUrl);
    }

    if (repository.getRepositoryKind().isFacetAvailable(MavenRepository.class)) {
      resource.setRepoPolicy(
          repository.adaptToFacet(MavenRepository.class).getRepositoryPolicy().toString());

      if (repository.getRepositoryKind().isFacetAvailable(MavenProxyRepository.class)) {
        resource.setChecksumPolicy(
            repository.adaptToFacet(MavenProxyRepository.class).getChecksumPolicy().toString());

        resource.setDownloadRemoteIndexes(
            repository.adaptToFacet(MavenProxyRepository.class).isDownloadRemoteIndexes());
      }
    }
    // as this is a required field on ui, we need this to be set for non-maven type repos
    else {
      resource.setRepoPolicy(RepositoryPolicy.MIXED.name());
      resource.setChecksumPolicy(ChecksumPolicy.IGNORE.name());
      resource.setDownloadRemoteIndexes(false);
    }

    return resource;
  }