Search in sources :

Example 11 with ManagedRepository

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

the class BrowseServiceTest method listUserRepositories.

@Test
public void listUserRepositories() throws Exception {
    initSourceTargetRepo();
    BrowseService browseService = getBrowseService(authorizationHeader, false);
    List<ManagedRepository> browseResult = browseService.getUserRepositories();
    assertThat(browseResult).isNotNull().isNotEmpty().hasSize(5);
    List<String> repIds = new ArrayList<>();
    for (ManagedRepository rep : browseResult) {
        repIds.add(rep.getId());
    }
    assertThat(repIds).contains("internal", "snapshots", "test-repo", "test-copy-target", "test-origin-repo");
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArrayList(java.util.ArrayList) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Test(org.junit.Test)

Example 12 with ManagedRepository

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

the class BrowseServiceTest method listUserManagableRepositories.

@Test
public void listUserManagableRepositories() throws Exception {
    initSourceTargetRepo();
    // Giving the guest user a manager role
    String name = "Repository Manager - internal";
    Role role = getRoleManagementService(authorizationHeader).getRole(name);
    role.setUsers(Arrays.asList(getUserService(authorizationHeader).getUser("guest")));
    getRoleManagementService(authorizationHeader).updateRoleUsers(role);
    // browseService with guest user
    BrowseService browseService = getBrowseService("", false);
    List<ManagedRepository> browseResult = browseService.getUserManagableRepositories();
    assertThat(browseResult).isNotNull().isNotEmpty().hasSize(1);
    List<String> repIds = new ArrayList<>();
    for (ManagedRepository rep : browseResult) {
        repIds.add(rep.getId());
    }
    assertThat(repIds).contains("internal");
}
Also used : Role(org.apache.archiva.redback.rest.api.model.Role) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArrayList(java.util.ArrayList) BrowseService(org.apache.archiva.rest.api.services.BrowseService) Test(org.junit.Test)

Example 13 with ManagedRepository

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

the class DefaultBrowseService method artifactAvailable.

@Override
public Boolean artifactAvailable(String groupId, String artifactId, String version, String classifier, String repositoryId) throws ArchivaRestServiceException {
    List<String> selectedRepos = getSelectedRepos(repositoryId);
    boolean snapshot = VersionUtil.isSnapshot(version);
    try {
        for (String repoId : selectedRepos) {
            ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repoId);
            if ((snapshot && !managedRepository.isSnapshots()) || (!snapshot && managedRepository.isSnapshots())) {
                continue;
            }
            ManagedRepositoryContent managedRepositoryContent = getManagedRepositoryContent(repoId);
            // FIXME default to jar which can be wrong for war zip etc....
            ArchivaArtifact archivaArtifact = new ArchivaArtifact(groupId, artifactId, version, StringUtils.isEmpty(classifier) ? "" : classifier, "jar", repoId);
            Path file = managedRepositoryContent.toFile(archivaArtifact);
            if (file != null && Files.exists(file)) {
                return true;
            }
            // in case of SNAPSHOT we can have timestamped version locally !
            if (StringUtils.endsWith(version, VersionUtil.SNAPSHOT)) {
                Path metadataFile = file.getParent().resolve(MetadataTools.MAVEN_METADATA);
                if (Files.exists(metadataFile)) {
                    try {
                        ArchivaRepositoryMetadata archivaRepositoryMetadata = MavenMetadataReader.read(metadataFile);
                        int buildNumber = archivaRepositoryMetadata.getSnapshotVersion().getBuildNumber();
                        String timeStamp = archivaRepositoryMetadata.getSnapshotVersion().getTimestamp();
                        // rebuild file name with timestamped version and build number
                        String timeStampFileName = // 
                        new StringBuilder(artifactId).append('-').append(// 
                        StringUtils.remove(version, "-" + VersionUtil.SNAPSHOT)).append('-').append(// 
                        timeStamp).append('-').append(// 
                        Integer.toString(buildNumber)).append(// 
                        (StringUtils.isEmpty(classifier) ? "" : "-" + classifier)).append(".jar").toString();
                        Path timeStampFile = file.getParent().resolve(timeStampFileName);
                        log.debug("try to find timestamped snapshot version file: {}", timeStampFile.toAbsolutePath());
                        if (Files.exists(timeStampFile)) {
                            return true;
                        }
                    } catch (XMLException e) {
                        log.warn("skip fail to find timestamped snapshot file: {}", e.getMessage());
                    }
                }
            }
            String path = managedRepositoryContent.toPath(archivaArtifact);
            file = connectors.fetchFromProxies(managedRepositoryContent, path);
            if (file != null && Files.exists(file)) {
                // download pom now
                String pomPath = StringUtils.substringBeforeLast(path, ".jar") + ".pom";
                connectors.fetchFromProxies(managedRepositoryContent, pomPath);
                return true;
            }
        }
    } catch (RepositoryAdminException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    } catch (RepositoryException e) {
        log.error(e.getMessage(), e);
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    return false;
}
Also used : Path(java.nio.file.Path) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) ArchivaArtifact(org.apache.archiva.model.ArchivaArtifact) XMLException(org.apache.archiva.xml.XMLException) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ArchivaRepositoryMetadata(org.apache.archiva.model.ArchivaRepositoryMetadata)

Example 14 with ManagedRepository

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

the class RepositoriesServiceTest method authorizedToDeleteArtifacts.

@Test
public void authorizedToDeleteArtifacts() throws Exception {
    ManagedRepository managedRepository = getTestManagedRepository("SOURCE_REPO_ID", "SOURCE_REPO_ID");
    try {
        getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
        RepositoriesService repositoriesService = getRepositoriesService(authorizationHeader);
        assertTrue(repositoriesService.isAuthorizedToDeleteArtifacts(managedRepository.getId()));
    } finally {
        cleanQuietlyRepo(managedRepository.getId());
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

Example 15 with ManagedRepository

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

the class RepositoriesServiceTest method notAuthorizedToDeleteArtifacts.

@Test
public void notAuthorizedToDeleteArtifacts() throws Exception {
    ManagedRepository managedRepository = getTestManagedRepository("SOURCE_REPO_ID", "SOURCE_REPO_ID");
    try {
        getManagedRepositoriesService(authorizationHeader).addManagedRepository(managedRepository);
        RepositoriesService repositoriesService = getRepositoriesService(guestAuthzHeader);
        assertFalse(repositoriesService.isAuthorizedToDeleteArtifacts(managedRepository.getId()));
    } finally {
        cleanQuietlyRepo(managedRepository.getId());
    }
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) RepositoriesService(org.apache.archiva.rest.api.services.RepositoriesService) ManagedRepositoriesService(org.apache.archiva.rest.api.services.ManagedRepositoriesService) Test(org.junit.Test)

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