use of org.apache.archiva.admin.model.beans.RepositoryGroup in project archiva by apache.
the class RepositoryGroupAdminTest method testAddGroupWithInvalidMergedIndexTtl.
@Test(expected = RepositoryAdminException.class)
public void testAddGroupWithInvalidMergedIndexTtl() throws Exception {
try {
ManagedRepository managedRepositoryOne = getTestManagedRepository("test-new-one", Paths.get(APPSERVER_BASE_PATH, "test-new-one").toString());
ManagedRepository managedRepositoryTwo = getTestManagedRepository("test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two").toString());
managedRepositoryAdmin.addManagedRepository(managedRepositoryOne, false, getFakeAuditInformation());
managedRepositoryAdmin.addManagedRepository(managedRepositoryTwo, false, getFakeAuditInformation());
RepositoryGroup repositoryGroup = new RepositoryGroup("repo-group-one", Arrays.asList("test-new-one", "test-new-two")).mergedIndexTtl(-1);
mockAuditListener.clearEvents();
repositoryGroupAdmin.addRepositoryGroup(repositoryGroup, getFakeAuditInformation());
} finally {
mockAuditListener.clearEvents();
repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-one"));
repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
}
}
use of org.apache.archiva.admin.model.beans.RepositoryGroup in project archiva by apache.
the class RepositoryGroupAdminTest method addAndDeleteGroupWithRemovedManagedRepo.
@Test
public void addAndDeleteGroupWithRemovedManagedRepo() throws Exception {
try {
ManagedRepository managedRepositoryOne = getTestManagedRepository("test-new-one", Paths.get(APPSERVER_BASE_PATH, "test-new-one").toString());
ManagedRepository managedRepositoryTwo = getTestManagedRepository("test-new-two", Paths.get(APPSERVER_BASE_PATH, "test-new-two").toString());
managedRepositoryAdmin.addManagedRepository(managedRepositoryOne, false, getFakeAuditInformation());
managedRepositoryAdmin.addManagedRepository(managedRepositoryTwo, false, getFakeAuditInformation());
RepositoryGroup repositoryGroup = new RepositoryGroup("repo-group-one", Arrays.asList("test-new-one", "test-new-two"));
mockAuditListener.clearEvents();
repositoryGroupAdmin.addRepositoryGroup(repositoryGroup, getFakeAuditInformation());
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
assertEquals(2, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
assertEquals(Arrays.asList("test-new-one", "test-new-two"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
// deleting a managed repo to validate repogroup correctly updated !
managedRepositoryAdmin.deleteManagedRepository("test-new-one", getFakeAuditInformation(), true);
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals("repo-group-one", repositoryGroupAdmin.getRepositoriesGroups().get(0).getId());
assertEquals(1, repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories().size());
assertEquals(Arrays.asList("test-new-two"), repositoryGroupAdmin.getRepositoriesGroups().get(0).getRepositories());
repositoryGroupAdmin.deleteRepositoryGroup("repo-group-one", getFakeAuditInformation());
assertEquals(0, repositoryGroupAdmin.getRepositoriesGroups().size());
assertEquals(3, mockAuditListener.getAuditEvents().size());
assertEquals(AuditEvent.ADD_REPO_GROUP, mockAuditListener.getAuditEvents().get(0).getAction());
assertEquals(AuditEvent.DELETE_MANAGED_REPO, mockAuditListener.getAuditEvents().get(1).getAction());
assertEquals(AuditEvent.DELETE_REPO_GROUP, mockAuditListener.getAuditEvents().get(2).getAction());
} finally {
mockAuditListener.clearEvents();
repositoryRegistry.removeRepository(repositoryRegistry.getRepository("test-new-two"));
}
}
use of org.apache.archiva.admin.model.beans.RepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupAdmin method deleteRepositoryFromGroup.
@Override
public Boolean deleteRepositoryFromGroup(String repositoryGroupId, String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
RepositoryGroup repositoryGroup = getRepositoryGroup(repositoryGroupId);
if (repositoryGroup == null) {
throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot remove repository from it");
}
if (!repositoryGroup.getRepositories().contains(repositoryId)) {
throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not contains repository with id" + repositoryId);
}
repositoryGroup.removeRepository(repositoryId);
updateRepositoryGroup(repositoryGroup, auditInformation, false);
triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.DELETE_REPO_FROM_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.admin.model.beans.RepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupAdmin method initialize.
@PostConstruct
public void initialize() {
String appServerBase = getRegistry().getString("appserver.base");
groupsDirectory = Paths.get(appServerBase, "groups");
if (!Files.exists(groupsDirectory)) {
Files.exists(groupsDirectory);
}
try {
for (RepositoryGroup repositoryGroup : getRepositoriesGroups()) {
mergedRemoteIndexesScheduler.schedule(repositoryGroup, getMergedIndexDirectory(repositoryGroup.getId()));
// create the directory for each group if not exists
Path groupPath = groupsDirectory.resolve(repositoryGroup.getId());
if (!Files.exists(groupPath)) {
try {
Files.createDirectories(groupPath);
} catch (IOException e) {
log.error("Could not create directory {}", groupPath);
}
}
}
} catch (RepositoryAdminException e) {
log.warn("fail to getRepositoriesGroups {}", e.getMessage(), e);
}
}
use of org.apache.archiva.admin.model.beans.RepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupAdmin method deleteRepositoryGroup.
@Override
public Boolean deleteRepositoryGroup(String repositoryGroupId, AuditInformation auditInformation) throws RepositoryAdminException {
Configuration configuration = getArchivaConfiguration().getConfiguration();
RepositoryGroupConfiguration repositoryGroupConfiguration = configuration.getRepositoryGroupsAsMap().get(repositoryGroupId);
mergedRemoteIndexesScheduler.unschedule(new RepositoryGroup(repositoryGroupId, Collections.<String>emptyList()));
if (repositoryGroupConfiguration == null) {
throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot remove");
}
configuration.removeRepositoryGroup(repositoryGroupConfiguration);
triggerAuditEvent(repositoryGroupId, null, AuditEvent.DELETE_REPO_GROUP, auditInformation);
return Boolean.TRUE;
}
Aggregations