Package org.sonatype.nexus.rest.model

Examples of org.sonatype.nexus.rest.model.RepositoryResource


  /**
   * 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 =
        ((AbstractRepository)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 =
        ((AbstractRepository)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;

  }
View Full Code Here


    return repoRes;
  }

  private RepositoryBaseResource createHosted(RepositoryTemplate template) {
    RepositoryResource repoRes = new RepositoryResource();

    repoRes.setRepoType("hosted");

    AbstractMavenRepositoryTemplate m2Template = (AbstractMavenRepositoryTemplate) template;
    repoRes.setRepoPolicy(m2Template.getRepositoryPolicy().name());

    ConfigurableRepository cfg = template.getConfigurableRepository();
    repoRes.setWritePolicy(cfg.getWritePolicy().name());
    repoRes.setBrowseable(cfg.isBrowseable());
    repoRes.setIndexable(cfg.isIndexable());
    repoRes.setExposed(cfg.isExposed());
    repoRes.setNotFoundCacheTTL(cfg.getNotFoundCacheTimeToLive());

    return repoRes;
  }
View Full Code Here

      exConf.setSynchronizeAtStartup(repoResource.isSyncAtStartup());

    }
    else if (!RepositoryBaseResourceConverter.REPO_TYPE_GROUP.equals(resource.getRepoType())) {
      RepositoryResource repoResource = (RepositoryResource) resource;

      // we can use the default if the value is empty
      if (StringUtils.isNotEmpty(repoResource.getWritePolicy())) {
        appModel.setWritePolicy(repoResource.getWritePolicy());
      }

      appModel.setBrowseable(repoResource.isBrowseable());

      appModel.setIndexable(repoResource.isIndexable());
      appModel.setSearchable(repoResource.isIndexable());

      appModel.setNotFoundCacheTTL(repoResource.getNotFoundCacheTTL());

      appModel.setExternalConfiguration(ex);

      M2RepositoryConfiguration exConf = new M2RepositoryConfiguration(ex);

      exConf.setRepositoryPolicy(EnumUtil.valueOf(repoResource.getRepoPolicy(), RepositoryPolicy.class));

      if (repoResource.getOverrideLocalStorageUrl() != null) {
        appModel.setLocalStorage(new CLocalStorage());

        appModel.getLocalStorage().setUrl(repoResource.getOverrideLocalStorageUrl());

        appModel.getLocalStorage().setProvider("file");
      }
      else {
        appModel.setLocalStorage(null);
      }

      RepositoryResourceRemoteStorage remoteStorage = repoResource.getRemoteStorage();
      if (remoteStorage != null) {
        appModel.setNotFoundCacheActive(true);

        appModel.setRemoteStorage(new CRemoteStorage());
View Full Code Here

      }
      else if (REPO_TYPE_PROXIED.equals(repoType)) {
        return new RepositoryProxyResource();
      }
      else if (REPO_TYPE_HOSTED.equals(repoType)) {
        return new RepositoryResource();
      }
      else if (REPO_TYPE_GROUP.equals(repoType)) {
        return new RepositoryGroupResource();
      }
      else {
View Full Code Here

            throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Virtual repository Not Found");
          }
        }
        else {
          RepositoryResource model = (RepositoryResource) resource;

          try {
            Repository repository = getRepositoryRegistry().getRepository(repoId);

            repository.setName(model.getName());

            repository.setExposed(resource.isExposed());

            // set null to read only
            RepositoryWritePolicy writePolicy =
                (model.getWritePolicy() != null) ? RepositoryWritePolicy.valueOf(model.getWritePolicy())
                    : RepositoryWritePolicy.READ_ONLY;

            repository.setWritePolicy(writePolicy);

            repository.setBrowseable(model.isBrowseable());

            repository.setIndexable(model.isIndexable());
            repository.setSearchable(model.isIndexable());

            repository.setNotFoundCacheTimeToLive(model.getNotFoundCacheTTL());

            if (repository.getRepositoryKind().isFacetAvailable(ProxyRepository.class)) {
              ProxyRepository proxyRepo = repository.adaptToFacet(ProxyRepository.class);

              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
                  .getRemoteAuthenticationSettings())) {
                oldPasswordForRemoteStorage =
                    ((UsernamePasswordRemoteAuthenticationSettings) proxyRepo
                        .getRemoteAuthenticationSettings()).getPassword();
              }

              RemoteAuthenticationSettings remoteAuth =
                  getAuthenticationInfoConverter().convertAndValidateFromModel(
                      this.convertAuthentication(model.getRemoteStorage().getAuthentication(),
                          oldPasswordForRemoteStorage));
              RemoteConnectionSettings remoteConnSettings =
                  getGlobalRemoteConnectionSettings().convertAndValidateFromModel(
                      this.convertRemoteConnectionSettings(model.getRemoteStorage()
                          .getConnectionSettings()));

              if (remoteAuth != null) {
                proxyRepo.setRemoteAuthenticationSettings(remoteAuth);
              }
              else {
                proxyRepo.getRemoteStorageContext().removeRemoteAuthenticationSettings();
              }

              if (remoteConnSettings != null) {
                proxyRepo.setRemoteConnectionSettings(remoteConnSettings);
              }
              else {
                proxyRepo.getRemoteStorageContext().removeRemoteConnectionSettings();
              }

              // set auto block
              proxyRepo.setAutoBlockActive(((RepositoryProxyResource) model).isAutoBlockActive());

              // set type validation
              proxyRepo.setFileTypeValidation(((RepositoryProxyResource) model).isFileTypeValidation());

            }

            if (repository.getRepositoryKind().isFacetAvailable(MavenRepository.class)) {
              RepositoryPolicy repoPolicy =
                  EnumUtil.valueOf(model.getRepoPolicy(), RepositoryPolicy.class);
              repository.adaptToFacet(MavenRepository.class).setRepositoryPolicy(repoPolicy);

              if (repository.getRepositoryKind().isFacetAvailable(MavenProxyRepository.class)) {
                ChecksumPolicy checksum =
                    EnumUtil.valueOf(model.getChecksumPolicy(), ChecksumPolicy.class);

                MavenProxyRepository pRepository = repository.adaptToFacet(MavenProxyRepository.class);
                pRepository.setChecksumPolicy(checksum);

                pRepository.setDownloadRemoteIndexes(model.isDownloadRemoteIndexes());

                pRepository.setChecksumPolicy(EnumUtil.valueOf(model.getChecksumPolicy(),
                    ChecksumPolicy.class));

                pRepository.setDownloadRemoteIndexes(model.isDownloadRemoteIndexes());

                RepositoryProxyResource proxyModel = (RepositoryProxyResource) model;

                pRepository.setArtifactMaxAge(proxyModel.getArtifactMaxAge());

                pRepository.setMetadataMaxAge(proxyModel.getMetadataMaxAge());

                if (proxyModel.getItemMaxAge() != null) {
                  pRepository.setItemMaxAge(proxyModel.getItemMaxAge());
                }
              }
            }
            else {
              // This is a total hack to be able to retrieve this data from a non core repo if available
              try {
                RepositoryProxyResource proxyModel = (RepositoryProxyResource) model;

                // NXCM-5131 Ask for itemMaxAge first, because it's already introduced in AbstractProxyRepository and
                // may be a superclass for non-maven repositories (e.g. NuGet)
                Method itemMethod =
                    repository.getClass().getMethod("setItemMaxAge", int.class);
                if (itemMethod != null && proxyModel.getItemMaxAge() != null) {
                  itemMethod.invoke(repository, proxyModel.getItemMaxAge());
                }

                Method artifactMethod =
                    repository.getClass().getMethod("setArtifactMaxAge", int.class);
                if (artifactMethod != null) {
                  artifactMethod.invoke(repository, proxyModel.getArtifactMaxAge());
                }

                Method metadataMethod =
                    repository.getClass().getMethod("setMetadataMaxAge", int.class);
                if (metadataMethod != null) {
                  metadataMethod.invoke(repository, proxyModel.getMetadataMaxAge());
                }
              }
              catch (Exception e) {
                // nothing to do here, doesn't support artifactmax age
              }
            }

            repository.setLocalUrl(model.getOverrideLocalStorageUrl());

            getNexusConfiguration().saveConfiguration();
          }
          catch (NoSuchRepositoryAccessException e) {
            getLogger().warn("Repository access denied, id=" + repoId);
View Full Code Here

  // SWITCHES ALLOW*

  public void allowBrowsing(String repositoryName, boolean allowBrowsing)
      throws IOException
  {
    RepositoryResource repository = getRepository(repositoryName);

    repository.setBrowseable(allowBrowsing);

    saveRepository(repository, repositoryName);
  }
View Full Code Here

  }

  public void allowSearch(String repositoryName, boolean allowSearch)
      throws IOException
  {
    RepositoryResource repository = getRepository(repositoryName);

    repository.setIndexable(allowSearch);

    saveRepository(repository, repositoryName);
  }
View Full Code Here

  }

  public void allowDeploying(String repositoryName, boolean allowDeploying)
      throws IOException
  {
    RepositoryResource repository = getRepository(repositoryName);

    if (allowDeploying) {
      repository.setWritePolicy(RepositoryWritePolicy.ALLOW_WRITE.name());
    }
    else {
      repository.setWritePolicy(RepositoryWritePolicy.READ_ONLY.name());
    }

    saveRepository(repository, repositoryName);
  }
View Full Code Here

      RepositoryShadowResource actual = (RepositoryShadowResource) responseResource;

      Assert.assertEquals(actual.getShadowOf(), expected.getShadowOf());
    }
    else {
      RepositoryResource expected = (RepositoryResource) repo;
      RepositoryResource actual = (RepositoryResource) responseResource;

      // Assert.assertEquals( expected.getChecksumPolicy(), actual.getChecksumPolicy() );

      // TODO: sometimes the storage dir ends with a '/' SEE: NEXUS-542
      if (actual.getDefaultLocalStorageUrl().endsWith("/")) {
        Assert.assertTrue("Unexpected defaultLocalStorage: <expected to end with> " + "/storage/"
            + repo.getId()
            + "/  <actual>" + actual.getDefaultLocalStorageUrl(),
            actual.getDefaultLocalStorageUrl().endsWith("/storage/" + repo.getId() + "/"));
      }
      // NOTE one of these blocks should be removed
      else {
        Assert.assertTrue("Unexpected defaultLocalStorage: <expected to end with> " + "/storage/"
            + repo.getId()
            + "  <actual>" + actual.getDefaultLocalStorageUrl(),
            actual.getDefaultLocalStorageUrl().endsWith("/storage/" + repo.getId()));
      }

      Assert.assertEquals(expected.getNotFoundCacheTTL(), actual.getNotFoundCacheTTL());
      // Assert.assertEquals( expected.getOverrideLocalStorageUrl(), actual.getOverrideLocalStorageUrl() );

      if (expected.getRemoteStorage() == null) {
        Assert.assertNull(actual.getRemoteStorage());
      }
      else {
        Assert.assertEquals(actual.getRemoteStorage().getRemoteStorageUrl(),
            expected.getRemoteStorage().getRemoteStorageUrl());
      }

      Assert.assertEquals(actual.getRepoPolicy(), expected.getRepoPolicy());
    }

    // check nexus.xml
    this.validateRepoInNexusConfig(responseResource);
  }
View Full Code Here

      // "Unknown shadow repo type='" + cRepo.getProviderRole() + cRepo.getProviderHint()
      // + "'!" );
      // Assert.assertEquals( expected.getFormat(), expectedCc.getId() );
    }
    else {
      RepositoryResource expected = (RepositoryResource) repo;
      CRepository cRepo = configUtil.getRepo(repo.getId());

      Assert.assertEquals(expected.getId(), cRepo.getId());

      Assert.assertEquals(expected.getName(), cRepo.getName());

      // cstamas: This is nonsense, this starts in-process (HERE) of nexus internals while IT runs a nexus too,
      // and they start/try to use same FS resources!
      // ContentClass expectedCc =
      // repositoryTypeRegistry.getRepositoryContentClass( cRepo.getProviderRole(), cRepo.getProviderHint() );
      // Assert.assertNotNull( expectedCc, "Unknown repo type='" + cRepo.getProviderRole() +
      // cRepo.getProviderHint()
      // + "'!" );
      // Assert.assertEquals( expected.getFormat(), expectedCc.getId() );

      Assert.assertEquals(expected.getNotFoundCacheTTL(), cRepo.getNotFoundCacheTTL());

      if (expected.getOverrideLocalStorageUrl() == null) {
        Assert.assertNull("Expected CRepo localstorage url not be set, because it is the default.",
            cRepo.getLocalStorage().getUrl());
      }
      else {
        String actualLocalStorage =
            cRepo.getLocalStorage().getUrl().endsWith("/") ? cRepo.getLocalStorage().getUrl()
                : cRepo.getLocalStorage().getUrl() + "/";
        String overridLocalStorage =
            expected.getOverrideLocalStorageUrl().endsWith("/") ? expected.getOverrideLocalStorageUrl()
                : expected.getOverrideLocalStorageUrl() + "/";
        Assert.assertEquals(actualLocalStorage, overridLocalStorage);
      }

      if (expected.getRemoteStorage() == null) {
        Assert.assertNull(cRepo.getRemoteStorage());
      }
      else {
        Assert.assertEquals(cRepo.getRemoteStorage().getUrl(),
            expected.getRemoteStorage().getRemoteStorageUrl());
      }

      // check maven repo props (for not just check everything that is a Repository
      if (expected.getProvider().matches("maven[12]")) {
        M2RepositoryConfiguration cM2Repo = configUtil.getM2Repo(repo.getId());

        if (expected.getChecksumPolicy() != null) {
          Assert.assertEquals(cM2Repo.getChecksumPolicy().name(), expected.getChecksumPolicy());
        }

        Assert.assertEquals(cM2Repo.getRepositoryPolicy().name(), expected.getRepoPolicy());
      }
    }

  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.rest.model.RepositoryResource

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.