Package org.sonatype.nexus.rest.model

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


    repo = (RepositoryResource) this.messageUtil.createRepository(repo);

    // now create a virtual one, this should fail

    // create a repository
    RepositoryShadowResource virtualRepo = new RepositoryShadowResource();

    virtualRepo.setId("testVirtualRepoWithSameId");
    virtualRepo.setRepoType("virtual"); // [hosted, proxy, virtual]
    virtualRepo.setName("testVirtualRepoWithSameId");
    virtualRepo.setProvider("m2-m1-shadow");
    // format is neglected by server from now on, provider is the new guy in the town
    virtualRepo.setFormat("maven1");
    virtualRepo.setShadowOf("testVirtualRepoWithSameId");
    Response response = this.messageUtil.sendMessage(Method.POST, virtualRepo);

    Assert.assertEquals("Status:" + "\n" + response.getEntity().getText(), response.getStatus().getCode(), 400);

  }
View Full Code Here


    // create shadow repo 'nexus-shadow-repo'
    RepositoryMessageUtil repoUtil = new RepositoryMessageUtil(this.getXMLXStream(), MediaType.APPLICATION_XML);
    String shadowRepoId = "nexus-shadow-repo";
    String taskName = "synchShadowTest";

    RepositoryShadowResource repo = new RepositoryShadowResource();
    repo.setId(shadowRepoId);
    repo.setProvider("m2-m1-shadow");
    // format is neglected by server from now on, provider is the new guy in the town
    repo.setFormat("maven1");
    repo.setName(shadowRepoId);
    repo.setRepoType("virtual");
    repo.setShadowOf(this.getTestRepositoryId());
    repo.setSyncAtStartup(false);
    repo.setExposed(true);
    repoUtil.createRepository(repo);

    // create Sync Repo Task
    // repo: 'nexus-shadow-repo'
    // recurrence: 'manual'
    // run it manually
    this.executeTask(taskName, repo.getId());

    // download the file using the shadow repo
    File actualFile =
        this.downloadFile(
            new URL(this.getBaseNexusUrl() + "content/repositories/" + shadowRepoId + "/" + this.getTestId()
View Full Code Here

    return result;
  }

  private RepositoryBaseResource createShadow(RepositoryTemplate template) {
    RepositoryShadowResource repoRes = new RepositoryShadowResource();

    repoRes.setRepoType("virtual");

    AbstractShadowRepositoryConfiguration cfg =
        (AbstractShadowRepositoryConfiguration) template.getConfigurableRepository().getCurrentCoreConfiguration()
            .getExternalConfiguration().getConfiguration(false);

    repoRes.setSyncAtStartup(cfg.isSynchronizeAtStartup());
    repoRes.setShadowOf(cfg.getMasterRepositoryId());

    return repoRes;
  }
View Full Code Here

    return resource;
  }

  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;
  }
View Full Code Here

    this.validateXmlHasNoPackageNames(resourceResponse);
  }

  @Test
  public void testRepositoryShadowResource() {
    RepositoryShadowResource repo = new RepositoryShadowResource();

    repo.setId("createTestRepo");
    repo.setRepoType("virtual");
    repo.setName("Create Test Repo");
    repo.setFormat("maven2");
    repo.setShadowOf("Shadow Of");
    repo.setSyncAtStartup(true);
    repo.setContentResourceURI("contentResourceURI");
    repo.setExposed(true);
    repo.setProvider("provider");
    repo.setProviderRole("providerrole");

    RepositoryResourceResponse resourceResponse = new RepositoryResourceResponse();
    resourceResponse.setData(repo);

    this.marshalUnmarchalThenCompare(resourceResponse);
View Full Code Here

      appModel.setExternalConfiguration(ex);

      // indexer is unaware of the m2 layout conversion
      appModel.setIndexable(false);

      RepositoryShadowResource repoResource = (RepositoryShadowResource) resource;

      M2LayoutedM1ShadowRepositoryConfiguration exConf = new M2LayoutedM1ShadowRepositoryConfiguration(ex);

      exConf.setMasterRepositoryId(repoResource.getShadowOf());

      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 {
        repoType = ((LookAheadStreamReader) reader.underlyingReader()).getFieldValue("repoType");
      }

      if (REPO_TYPE_VIRTUAL.equals(repoType)) {
        return new RepositoryShadowResource();
      }
      else if (REPO_TYPE_PROXIED.equals(repoType)) {
        return new RepositoryProxyResource();
      }
      else if (REPO_TYPE_HOSTED.equals(repoType)) {
View Full Code Here

    if (repoRequest != null) {
      try {
        RepositoryBaseResource resource = repoRequest.getData();

        if (RepositoryBaseResourceConverter.REPO_TYPE_VIRTUAL.equals(resource.getRepoType())) {
          RepositoryShadowResource model = (RepositoryShadowResource) resource;

          try {
            ShadowRepository shadow =
                getRepositoryRegistry().getRepositoryWithFacet(repoId, ShadowRepository.class);

            shadow.setName(model.getName());

            shadow.setExposed(resource.isExposed());

            shadow.setMasterRepository(getRepositoryRegistry().getRepository(model.getShadowOf()));

            shadow.setSynchronizeAtStartup(model.isSyncAtStartup());

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

            throw new ResourceException(Status.CLIENT_ERROR_FORBIDDEN, "Access Denied to Repository");
          }
          catch (NoSuchRepositoryException e) {
            getLogger().warn("Virtual repository not found, id=" + repoId);

            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

    // Assert.assertEquals( repo.getFormat(), responseResource.getFormat() );
    Assert.assertEquals(responseResource.getRepoType(), repo.getRepoType());

    if (repo.getRepoType().equals("virtual")) {
      // check mirror
      RepositoryShadowResource expected = (RepositoryShadowResource) repo;
      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

  {
    NexusConfigUtil configUtil = new NexusConfigUtil();

    if (repo.getRepoType().equals("virtual")) {
      // check mirror
      RepositoryShadowResource expected = (RepositoryShadowResource) repo;
      CRepository cRepo = configUtil.getRepo(repo.getId());
      M2LayoutedM1ShadowRepositoryConfiguration cShadowRepo = configUtil.getRepoShadow(repo.getId());

      Assert.assertEquals(cShadowRepo.getMasterRepositoryId(), expected.getShadowOf());
      Assert.assertEquals(cRepo.getId(), expected.getId());
      Assert.assertEquals(cRepo.getName(), expected.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 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.RepositoryShadowResource

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.