Package org.sonatype.nexus.templates.repository

Examples of org.sonatype.nexus.templates.repository.RepositoryTemplate


      throws ResourceException
  {
    RepositoryResourceResponse result = new RepositoryResourceResponse();

    try {
      RepositoryTemplate template = getRepositoryTemplateById(getRepositoryId(request));

      RepositoryBaseResource repoRes = null;

      if (ProxyRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes = createProxy(template);
      }
      else if (HostedRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes = createHosted(template);
      }
      else if (ShadowRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes = createShadow(template);
      }
      else if (GroupRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes = new RepositoryGroupResource();

        repoRes.setRepoType("group");
      }
      else {
        // huh?
        throw new ResourceException(Status.SERVER_ERROR_INTERNAL, "Unrecognized repository template with ID='"
            + template.getId() + "' and mainFacet='" + template.getMainFacet().getName() + "'!");
      }

      repoRes.setId(template.getId());

      repoRes.setName(template.getDescription());

      repoRes.setProvider(template.getRepositoryProviderHint());

      repoRes.setProviderRole(template.getRepositoryProviderRole());

      repoRes.setFormat(template.getContentClass().getId());

      result.setData(repoRes);
    }
    catch (NoSuchTemplateIdException e) {
      throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, e.getMessage());
View Full Code Here


    RepositoryListResource repoRes;

    TemplateSet repoTemplates = getRepositoryTemplates();

    for (Template tmp : repoTemplates) {
      RepositoryTemplate template = (RepositoryTemplate) tmp;

      repoRes = new RepositoryListResource();

      repoRes.setResourceURI(createChildReference(request, this, template.getId()).toString());

      repoRes.setId(template.getId());

      repoRes.setName(template.getDescription());

      if (ProxyRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes.setRepoType("proxy");
      }
      else if (HostedRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes.setRepoType("hosted");
      }
      else if (ShadowRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes.setRepoType("virtual");
      }
      else if (GroupRepository.class.isAssignableFrom(template.getMainFacet())) {
        repoRes.setRepoType("group");
      }
      else {
        // huh?
        repoRes.setRepoType(template.getMainFacet().getName());
      }

      // policy
      // another hack
      if (template.getCoreConfiguration().getExternalConfiguration()
          .getConfiguration(false) instanceof AbstractMavenRepositoryConfiguration) {
        repoRes.setRepoPolicy(((AbstractMavenRepositoryConfiguration) template.getCoreConfiguration()
            .getExternalConfiguration().getConfiguration(false)).getRepositoryPolicy().toString());
      }

      // format
      repoRes.setFormat(template.getContentClass().getId());

      // userManaged
      repoRes.setUserManaged(template.getConfigurableRepository().isUserManaged());

      // exposed
      repoRes.setExposed(template.getConfigurableRepository().isExposed());

      // ==
      // below are not used for templates (and does not make any sense)
      // effectiveLocalStorageUrl
      // remoteUri
View Full Code Here

  {
    try {
      ContentClass contentClass =
          repositoryTypeRegistry.getRepositoryContentClass(GroupRepository.class, model.getProvider());

      RepositoryTemplate template = (RepositoryTemplate) getRepositoryTemplates().getTemplates(
          GroupRepository.class, contentClass, new ProviderHint(model.getProvider())
      ).pick();

      template.getConfigurableRepository().setId(model.getId());

      template.getConfigurableRepository().setName(model.getName());

      template.getConfigurableRepository().setExposed(model.isExposed());

      template.getConfigurableRepository().setLocalStatus(LocalStatus.IN_SERVICE);

      // we create an empty group
      GroupRepository groupRepository = (GroupRepository) template.create();

      ArrayList<String> memberIds = new ArrayList<String>(model.getRepositories().size());

      for (RepositoryGroupMemberRepository member : (List<RepositoryGroupMemberRepository>) model
          .getRepositories()) {
View Full Code Here

  @Test
  public void testTypeLimitationOverstep()
      throws Exception
  {
    RepositoryTemplate template = getTemplate();

    RepositoryTypeDescriptor rtd =
        repositoryTypeRegistry.getRepositoryTypeDescriptor(template.getConfigurableRepository().getProviderRole(),
            template.getConfigurableRepository().getProviderHint());

    // FIXME: this number here depends on _default_ config nexus uses!
    // We set limit to 3, since default-config contains 1 group, and we will add 3.
    // The 3rd and after of additions should fail with ConfigurationException!
    nexusConfiguration().setRepositoryMaxInstanceCount(rtd, 3);
View Full Code Here

  protected void createRepository(long repoIdLong, boolean shouldFail)
      throws Exception
  {
    String repoId = Long.toString(repoIdLong);

    RepositoryTemplate template = getTemplate();

    template.getConfigurableRepository().setId(repoId);
    template.getConfigurableRepository().setName(repoId);
    template.getConfigurableRepository().setExposed(true);
    template.getConfigurableRepository().setLocalStatus(LocalStatus.IN_SERVICE);

    boolean passed = false;

    try {
      template.create();

      passed = !shouldFail;
    }
    catch (ConfigurationException e) {
      passed = shouldFail;
View Full Code Here

  public void testCreateIndexableM1()
      throws Exception
  {
    String repoId = "indexableM1";

    RepositoryTemplate repoTemplate =
        (RepositoryTemplate) getRepositoryTemplates().getTemplates(Maven1HostedRepositoryTemplate.class,
            RepositoryPolicy.RELEASE).pick();

    repoTemplate.getConfigurableRepository().setId(repoId);
    repoTemplate.getConfigurableRepository().setName(repoId + "-name");
    // Assert.assertEquals( "group-name", group.getName() );
    repoTemplate.getConfigurableRepository().setExposed(true);
    repoTemplate.getConfigurableRepository().setLocalStatus(LocalStatus.IN_SERVICE);

    repoTemplate.getConfigurableRepository().setIndexable(true);

    // will not fail, just create a warning and silently override it
    Repository repository = repoTemplate.create();

    assertFalse("The repository should be non-indexable!", repository.isIndexable());
  }
View Full Code Here

  public void testCreateIndexableM2()
      throws Exception
  {
    String repoId = "indexableM2";

    RepositoryTemplate repoTemplate =
        (RepositoryTemplate) getRepositoryTemplates().getTemplates(Maven2HostedRepositoryTemplate.class)
            .getTemplates(RepositoryPolicy.RELEASE).pick();

    repoTemplate.getConfigurableRepository().setId(repoId);
    repoTemplate.getConfigurableRepository().setName(repoId + "-name");
    // Assert.assertEquals( "group-name", group.getName() );
    repoTemplate.getConfigurableRepository().setExposed(true);
    repoTemplate.getConfigurableRepository().setLocalStatus(LocalStatus.IN_SERVICE);
    repoTemplate.getConfigurableRepository().setIndexable(true);

    repoTemplate.create();
  }
View Full Code Here

  public void testCreateNonIndexableM2()
      throws Exception
  {
    String repoId = "nonIndexableM2";

    RepositoryTemplate repoTemplate =
        (RepositoryTemplate) getRepositoryTemplates().getTemplates(Maven2HostedRepositoryTemplate.class)
            .getTemplates(RepositoryPolicy.RELEASE).pick();

    repoTemplate.getConfigurableRepository().setId(repoId);
    repoTemplate.getConfigurableRepository().setName(repoId + "-name");
    // Assert.assertEquals( "group-name", group.getName() );
    repoTemplate.getConfigurableRepository().setExposed(true);
    repoTemplate.getConfigurableRepository().setLocalStatus(LocalStatus.IN_SERVICE);
    repoTemplate.getConfigurableRepository().setIndexable(false);

    repoTemplate.create();
  }
View Full Code Here

    catch (NoSuchRepositoryException e) {
      // good, it should be not present
    }

    // create this new repo type
    final RepositoryTemplate template =
        (RepositoryTemplate) templateManager.getTemplates().getTemplateById("nexus4807");
    template.getConfigurableRepository().setId("peter");
    template.getConfigurableRepository().setName("We all love Peter!");
    final Repository repository = template.create();

    // do some simple assertion
    assertThat(repository.getId(), equalTo("peter"));
    assertThat(repository.getName(), equalTo("We all love Peter!"));
    // assert peter is here simply, by having this below not throw any exception and returning non-null
View Full Code Here

  @Test
  public void testRepositoryRebuildAttributes()
      throws IOException
  {
    try {
      RepositoryTemplate hostedRepoTemplate =
          (RepositoryTemplate) templateManager.getTemplates()
              .getTemplates(Maven2HostedRepositoryTemplate.class).getTemplates(RepositoryPolicy.RELEASE)
              .pick();

      hostedRepoTemplate.getConfigurableRepository().setId("test");
      hostedRepoTemplate.getConfigurableRepository().setName("Test");
      hostedRepoTemplate.getConfigurableRepository().setLocalStatus(LocalStatus.IN_SERVICE);

      hostedRepoTemplate.create().recreateAttributes(new ResourceStoreRequest(RepositoryItemUid.PATH_ROOT), null);
    }
    catch (ConfigurationException e) {
      Assert.fail("ConfigurationException creating repository");
    }
  }
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.templates.repository.RepositoryTemplate

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.