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