Search in sources :

Example 1 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class RepositoryGroupServiceTest method addAndDelete.

@Test
public void addAndDelete() throws Exception {
    RepositoryGroupService service = getRepositoryGroupService();
    WebClient.client(service).header("Authorization", authorizationHeader);
    WebClient.client(service).header("Referer", "http://localhost:" + port);
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000);
    assertTrue(service.getRepositoriesGroups().isEmpty());
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(authorizationHeader);
    WebClient.getConfig(service).getHttpConduit().getClient().setReceiveTimeout(300000);
    ManagedRepository managedRepository = getTestManagedRepository();
    managedRepositoriesService.addManagedRepository(managedRepository);
    RepositoryGroup repositoryGroup = new RepositoryGroup("one", Arrays.asList(managedRepository.getId())).mergedIndexTtl(40);
    service.addRepositoryGroup(repositoryGroup);
    assertFalse(service.getRepositoriesGroups().isEmpty());
    assertEquals(1, service.getRepositoriesGroups().size());
    assertEquals(40, service.getRepositoriesGroups().get(0).getMergedIndexTtl());
    service.deleteRepositoryGroup("one");
    assertTrue(service.getRepositoriesGroups().isEmpty());
    assertEquals(0, service.getRepositoriesGroups().size());
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoryGroupService(org.apache.archiva.rest.api.services.RepositoryGroupService) Test(org.junit.Test)

Example 2 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class AbstractArchivaRestTest method createAndIndexRepo.

protected void createAndIndexRepo(String testRepoId, String repoPath, boolean stageNeeded) throws ArchivaRestServiceException, IOException, RedbackServiceException {
    if (getManagedRepositoriesService(authorizationHeader).getManagedRepository(testRepoId) != null) {
        getManagedRepositoriesService(authorizationHeader).deleteManagedRepository(testRepoId, false);
    }
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(testRepoId);
    managedRepository.setName("test repo");
    Path badContent = Paths.get(repoPath, "target");
    if (Files.exists(badContent)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(badContent);
    }
    Path file = Paths.get(repoPath);
    if (!file.isAbsolute()) {
        repoPath = getBasedir() + "/" + repoPath;
    }
    managedRepository.setLocation(Paths.get(repoPath).toString());
    String suffix = Long.toString(new Date().getTime());
    String baseDir = System.getProperty("java.io.tmpdir");
    managedRepository.setIndexDirectory(baseDir + "/.indexer-" + suffix);
    managedRepository.setPackedIndexDirectory(baseDir + "/.index-" + suffix);
    managedRepository.setStageRepoNeeded(stageNeeded);
    managedRepository.setSnapshots(true);
    // managedRepository.setScanned( scanned );
    ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
    service.addManagedRepository(managedRepository);
    getRoleManagementService(authorizationHeader).assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin");
    getRoleManagementService(authorizationHeader).assignTemplatedRole(ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "guest");
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Date(java.util.Date)

Example 3 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class ManagedRepositoriesServiceTest method getManagedRepositoryStatistics.

@Test
public void getManagedRepositoryStatistics() throws Exception {
    String testRepoId = "test-repo";
    // force guest user creation if not exists
    if (getUserService(authorizationHeader).getGuestUser() == null) {
        assertNotNull(getUserService(authorizationHeader).createGuestUser());
    }
    RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
    createAndIndexRepo(testRepoId, Paths.get(System.getProperty("basedir"), "src/test/repo-with-osgi").toAbsolutePath().toString());
    repositoriesService.scanRepositoryDirectoriesNow(testRepoId);
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(testRepoId)) {
        Thread.sleep(500);
        timeout -= 500;
    }
    ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
    ArchivaRepositoryStatistics archivaRepositoryStatistics = service.getManagedRepositoryStatistics(testRepoId, "en");
    assertNotNull(archivaRepositoryStatistics);
    log.info("archivaRepositoryStatistics: {}", archivaRepositoryStatistics.toString());
    assertEquals(92, archivaRepositoryStatistics.getNewFileCount());
    assertEquals(92, archivaRepositoryStatistics.getTotalFileCount());
    deleteTestRepo(testRepoId);
}
Also used : ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) ArchivaRepositoryStatistics(org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Example 4 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class ManagedRepositoriesServiceTest method fileLocationExists.

// @Test
public void fileLocationExists() throws Exception {
    ManagedRepositoriesService service = getManagedRepositoriesService(authorizationHeader);
    Path target = Paths.get("target");
    assertTrue(service.fileLocationExists(target.toAbsolutePath().toString()));
    // normally should not exists :-)
    assertFalse(service.fileLocationExists("/fooofofof/foddfdofd/dedede/kdeo"));
}
Also used : Path(java.nio.file.Path) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService)

Example 5 with ManagedRepositoriesService

use of org.apache.archiva.rest.api.services.ManagedRepositoriesService in project archiva by apache.

the class DownloadMergedIndexNonDefaultPathTest method downloadMergedIndexWithNonDefaultPath.

@Test
public void downloadMergedIndexWithNonDefaultPath() throws Exception {
    Path indexBaseDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("archiva").resolve("remotedownloadtest");
    String indexBase = indexBaseDir.toString();
    FileUtils.deleteQuietly(indexBaseDir);
    if (!Files.exists(indexBaseDir)) {
        Files.createDirectories(indexBaseDir);
    }
    String id = Long.toString(System.currentTimeMillis());
    ManagedRepository managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(indexBase + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/indexPacked-" + id);
    ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService();
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    RepositoriesService repositoriesService = getRepositoriesService();
    repositoriesService.scanRepositoryNow(id, true);
    // wait a bit to ensure index is finished
    int timeout = 20000;
    while (timeout > 0 && repositoriesService.alreadyScanning(id)) {
        Thread.sleep(500);
        timeout -= 500;
    }
    RepositoryGroupService repositoryGroupService = getRepositoryGroupService();
    String repoGroupId = "test-group";
    if (repositoryGroupService.getRepositoryGroup(repoGroupId) != null) {
        repositoryGroupService.deleteRepositoryGroup(repoGroupId);
    }
    RepositoryGroup repositoryGroup = new RepositoryGroup();
    repositoryGroup.setId(repoGroupId);
    String path = ".fooooo";
    repositoryGroup.setRepositories(Arrays.asList(id));
    repositoryGroup.setMergedIndexPath(path);
    repositoryGroupService.addRepositoryGroup(repositoryGroup);
    // create a repo with a remote on the one with index
    id = Long.toString(System.currentTimeMillis());
    managedRepository = new ManagedRepository(Locale.getDefault());
    managedRepository.setId(id);
    managedRepository.setName("name of " + id);
    managedRepository.setLocation(System.getProperty("basedir") + "/src/test/repositories/test-repo");
    managedRepository.setIndexDirectory(indexBaseDir + "/index-" + id);
    managedRepository.setPackedIndexDirectory(indexBase + "/tmpIndexPacked-" + id);
    if (managedRepositoriesService.getManagedRepository(id) != null) {
        managedRepositoriesService.deleteManagedRepository(id, false);
    }
    getManagedRepositoriesService().addManagedRepository(managedRepository);
    String remoteId = Long.toString(System.currentTimeMillis());
    RemoteRepository remoteRepository = new RemoteRepository(Locale.getDefault());
    remoteRepository.setId(remoteId);
    remoteRepository.setName(remoteId);
    remoteRepository.setDownloadRemoteIndex(true);
    remoteRepository.setUrl("http://localhost:" + port + "/repository/test-group");
    remoteRepository.setRemoteIndexUrl("http://localhost:" + port + "/repository/test-group/" + path);
    remoteRepository.setUserName(RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME);
    remoteRepository.setPassword(FakeCreateAdminService.ADMIN_TEST_PWD);
    getRemoteRepositoriesService().addRemoteRepository(remoteRepository);
    ProxyConnectorService proxyConnectorService = getProxyConnectorService();
    ProxyConnector proxyConnector = new ProxyConnector();
    proxyConnector.setProxyId("foo-bar2");
    proxyConnector.setSourceRepoId(id);
    proxyConnector.setTargetRepoId(remoteId);
    proxyConnectorService.addProxyConnector(proxyConnector);
    repositoriesService.scheduleDownloadRemoteIndex(remoteId, true, true);
    // wait the end
    while (!repositoriesService.getRunningRemoteDownloadIds().getStrings().isEmpty()) {
        Thread.sleep(500);
        log.debug("still running remote download");
    }
    SearchService searchService = getSearchService();
    SearchRequest request = new SearchRequest();
    request.setRepositories(Arrays.asList(id));
    request.setGroupId("org.apache.felix");
    List<Artifact> artifacts = searchService.searchArtifacts(request);
    assertThat(artifacts).isNotNull().isNotEmpty().hasSize(1);
}
Also used : Path(java.nio.file.Path) SearchRequest(org.apache.archiva.rest.api.model.SearchRequest) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ProxyConnectorService(org.apache.archiva.rest.api.services.ProxyConnectorService) RemoteRepository(org.apache.archiva.admin.model.beans.RemoteRepository) Artifact(org.apache.archiva.maven2.model.Artifact) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) SearchService(org.apache.archiva.rest.api.services.SearchService) RepositoryGroupService(org.apache.archiva.rest.api.services.RepositoryGroupService) ProxyConnector(org.apache.archiva.admin.model.beans.ProxyConnector) Test(org.junit.Test)

Aggregations

ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)12 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)8 Test (org.junit.Test)8 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 Path (java.nio.file.Path)6 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)3 RepositoryGroupService (org.apache.archiva.rest.api.services.RepositoryGroupService)3 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)2 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)2 Artifact (org.apache.archiva.maven2.model.Artifact)2 SearchRequest (org.apache.archiva.rest.api.model.SearchRequest)2 ProxyConnectorService (org.apache.archiva.rest.api.services.ProxyConnectorService)2 SearchService (org.apache.archiva.rest.api.services.SearchService)2 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)1 Date (java.util.Date)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 RoleManagementService (org.apache.archiva.redback.rest.api.services.RoleManagementService)1 ArchivaRepositoryStatistics (org.apache.archiva.rest.api.model.ArchivaRepositoryStatistics)1 HttpWagon (org.apache.maven.wagon.providers.http.HttpWagon)1