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");
}
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");
}
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;
}
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());
}
}
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());
}
}
Aggregations