Search in sources :

Example 16 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository 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 17 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository 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 18 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class AbstractArchivaRestTest method initSourceTargetRepo.

protected void initSourceTargetRepo() throws Exception {
    Path targetRepo = Paths.get("target/test-repo-copy");
    if (Files.exists(targetRepo)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(targetRepo);
    }
    assertFalse(Files.exists(targetRepo));
    Files.createDirectories(targetRepo);
    if (getManagedRepositoriesService(authorizationHeader).getManagedRepository(TARGET_REPO_ID) != null) {
        getManagedRepositoriesService(authorizationHeader).deleteManagedRepository(TARGET_REPO_ID, true);
        assertNull(getManagedRepositoriesService(authorizationHeader).getManagedRepository(TARGET_REPO_ID));
    }
    ManagedRepository managedRepository = getTestManagedRepository();
    managedRepository.setId(TARGET_REPO_ID);
    managedRepository.setLocation(targetRepo.toAbsolutePath().toString());
    managedRepository.setCronExpression("* * * * * ?");
    getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
    assertNotNull(getManagedRepositoriesService(authorizationHeader).getManagedRepository(TARGET_REPO_ID));
    Path originRepo = Paths.get("target/test-origin-repo");
    if (Files.exists(originRepo)) {
        org.apache.archiva.common.utils.FileUtils.deleteDirectory(originRepo);
    }
    assertFalse(Files.exists(originRepo));
    FileUtils.copyDirectory(Paths.get("src/test/repo-with-osgi").toAbsolutePath().toFile(), originRepo.toAbsolutePath().toFile());
    if (getManagedRepositoriesService(authorizationHeader).getManagedRepository(SOURCE_REPO_ID) != null) {
        getManagedRepositoriesService(authorizationHeader).deleteManagedRepository(SOURCE_REPO_ID, true);
        assertNull(getManagedRepositoriesService(authorizationHeader).getManagedRepository(SOURCE_REPO_ID));
    }
    managedRepository = getTestManagedRepository();
    managedRepository.setId(SOURCE_REPO_ID);
    managedRepository.setLocation(originRepo.toAbsolutePath().toString());
    getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
    assertNotNull(getManagedRepositoriesService(authorizationHeader).getManagedRepository(SOURCE_REPO_ID));
    getArchivaAdministrationService().enabledKnownContentConsumer("create-missing-checksums");
    getArchivaAdministrationService().enabledKnownContentConsumer("metadata-updater");
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository)

Example 19 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DefaultFileUploadService method save.

@Override
public Boolean save(String repositoryId, String groupId, String artifactId, String version, String packaging, boolean generatePom) throws ArchivaRestServiceException {
    repositoryId = StringUtils.trim(repositoryId);
    groupId = StringUtils.trim(groupId);
    artifactId = StringUtils.trim(artifactId);
    version = StringUtils.trim(version);
    packaging = StringUtils.trim(packaging);
    List<FileMetadata> fileMetadatas = getSessionFilesList();
    if (fileMetadatas == null || fileMetadatas.isEmpty()) {
        return Boolean.FALSE;
    }
    try {
        ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repositoryId);
        if (managedRepository == null) {
            // TODO i18n ?
            throw new ArchivaRestServiceException("Cannot find managed repository with id " + repositoryId, Response.Status.BAD_REQUEST.getStatusCode(), null);
        }
        if (VersionUtil.isSnapshot(version) && !managedRepository.isSnapshots()) {
            // TODO i18n ?
            throw new ArchivaRestServiceException("Managed repository with id " + repositoryId + " do not accept snapshots", Response.Status.BAD_REQUEST.getStatusCode(), null);
        }
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    // get from the session file with groupId/artifactId
    Iterable<FileMetadata> filesToAdd = Iterables.filter(fileMetadatas, new Predicate<FileMetadata>() {

        public boolean apply(FileMetadata fileMetadata) {
            return fileMetadata != null && !fileMetadata.isPomFile();
        }
    });
    Iterator<FileMetadata> iterator = filesToAdd.iterator();
    boolean pomGenerated = false;
    while (iterator.hasNext()) {
        FileMetadata fileMetadata = iterator.next();
        log.debug("fileToAdd: {}", fileMetadata);
        saveFile(repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version, packaging);
        pomGenerated = true;
        deleteFile(fileMetadata.getServerFileName());
    }
    filesToAdd = Iterables.filter(fileMetadatas, new Predicate<FileMetadata>() {

        @Override
        public boolean apply(FileMetadata fileMetadata) {
            return fileMetadata != null && fileMetadata.isPomFile();
        }
    });
    iterator = filesToAdd.iterator();
    while (iterator.hasNext()) {
        FileMetadata fileMetadata = iterator.next();
        log.debug("fileToAdd: {}", fileMetadata);
        savePomFile(repositoryId, fileMetadata, groupId, artifactId, version, packaging);
        deleteFile(fileMetadata.getServerFileName());
    }
    return Boolean.TRUE;
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) FileMetadata(org.apache.archiva.web.model.FileMetadata) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) Predicate(com.google.common.base.Predicate)

Example 20 with ManagedRepository

use of org.apache.archiva.admin.model.beans.ManagedRepository in project archiva by apache.

the class DefaultMergeRepositoriesService method doMerge.

protected void doMerge(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Aggregations

ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)46 Test (org.junit.Test)23 Path (java.nio.file.Path)20 AbstractRepositoryAdminTest (org.apache.archiva.admin.repository.AbstractRepositoryAdminTest)11 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)10 ManagedRepositoriesService (org.apache.archiva.rest.api.services.ManagedRepositoriesService)10 RepositoryGroup (org.apache.archiva.admin.model.beans.RepositoryGroup)9 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)8 ArrayList (java.util.ArrayList)7 RepositoriesService (org.apache.archiva.rest.api.services.RepositoriesService)7 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)5 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)5 RepositoryException (org.apache.archiva.repository.RepositoryException)5 IOException (java.io.IOException)4 Date (java.util.Date)4 ArchivaRepositoryMetadata (org.apache.archiva.model.ArchivaRepositoryMetadata)4 ArtifactReference (org.apache.archiva.model.ArtifactReference)4 ProxyConnector (org.apache.archiva.admin.model.beans.ProxyConnector)3 RemoteRepository (org.apache.archiva.admin.model.beans.RemoteRepository)3 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)3