use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class ArchivaConfigurationTest method testRemoveLastElements.
@Test
public void testRemoveLastElements() throws Exception {
Path baseFile = getTestFile("target/test/test-file.xml");
Files.deleteIfExists(baseFile);
assertFalse(Files.exists(baseFile));
Path userFile = getTestFile("target/test/test-file-user.xml");
Files.deleteIfExists(userFile);
assertFalse(Files.exists(userFile));
Files.createDirectories(baseFile.getParent());
FileUtils.copyFile(getTestFile("src/test/conf/conf-single-list-elements.xml").toFile(), baseFile.toFile());
Files.createDirectories(userFile.getParent());
FileUtils.writeStringToFile(userFile.toFile(), "<configuration/>", Charset.forName("UTF-8"));
ArchivaConfiguration archivaConfiguration = lookup(ArchivaConfiguration.class, "test-remove-central");
archivaConfiguration.reload();
Configuration configuration = archivaConfiguration.getConfiguration();
RepositoryGroupConfiguration repositoryGroup = configuration.getRepositoryGroups().get(0);
assertNotNull(repositoryGroup);
configuration.removeRepositoryGroup(repositoryGroup);
assertTrue(configuration.getRepositoryGroups().isEmpty());
RemoteRepositoryConfiguration repository = configuration.getRemoteRepositoriesAsMap().get("central");
assertNotNull(repository);
configuration.removeRemoteRepository(repository);
assertTrue(configuration.getRemoteRepositories().isEmpty());
ManagedRepositoryConfiguration managedRepository = configuration.getManagedRepositoriesAsMap().get("snapshots");
assertNotNull(managedRepository);
configuration.removeManagedRepository(managedRepository);
assertTrue(configuration.getManagedRepositories().isEmpty());
ProxyConnectorConfiguration proxyConnector = configuration.getProxyConnectors().get(0);
assertNotNull(proxyConnector);
configuration.removeProxyConnector(proxyConnector);
assertTrue(configuration.getProxyConnectors().isEmpty());
NetworkProxyConfiguration networkProxy = configuration.getNetworkProxiesAsMap().get("proxy");
assertNotNull(networkProxy);
configuration.removeNetworkProxy(networkProxy);
assertTrue(configuration.getNetworkProxies().isEmpty());
LegacyArtifactPath path = configuration.getLegacyArtifactPaths().get(0);
assertNotNull(path);
configuration.removeLegacyArtifactPath(path);
assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
RepositoryScanningConfiguration scanning = configuration.getRepositoryScanning();
String consumer = scanning.getKnownContentConsumers().get(0);
assertNotNull(consumer);
scanning.removeKnownContentConsumer(consumer);
// default values
assertFalse(scanning.getKnownContentConsumers().isEmpty());
consumer = scanning.getInvalidContentConsumers().get(0);
assertNotNull(consumer);
scanning.removeInvalidContentConsumer(consumer);
assertTrue(scanning.getInvalidContentConsumers().isEmpty());
archivaConfiguration.save(configuration);
archivaConfiguration = lookup(ArchivaConfiguration.class, "test-read-saved");
configuration = archivaConfiguration.getConfiguration();
assertNull(configuration.getRemoteRepositoriesAsMap().get("central"));
assertTrue(configuration.getRepositoryGroups().isEmpty());
assertNull(configuration.getManagedRepositoriesAsMap().get("snapshots"));
assertTrue(configuration.getProxyConnectors().isEmpty());
assertNull(configuration.getNetworkProxiesAsMap().get("proxy"));
assertTrue(configuration.getLegacyArtifactPaths().isEmpty());
scanning = configuration.getRepositoryScanning();
assertFalse(scanning.getKnownContentConsumers().isEmpty());
assertTrue(scanning.getInvalidContentConsumers().isEmpty());
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultRepositoryGroupService method updateRepositoryGroup.
@Override
public RepositoryGroup updateRepositoryGroup(final String repositoryGroupId, final RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (!repositoryRegistry.hasRepositoryGroup(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND), 404);
}
repositoryGroup.setId(repositoryGroupId);
try {
RepositoryGroupConfiguration configuration = toConfig(repositoryGroup);
CheckedResult<org.apache.archiva.repository.RepositoryGroup, Map<String, List<ValidationError>>> validationResult = repositoryRegistry.putRepositoryGroupAndValidate(configuration);
if (validationResult.isValid()) {
httpServletResponse.setStatus(201);
return RepositoryGroup.of(validationResult.getRepository());
} else {
throw ValidationException.of(validationResult.getResult());
}
} catch (RepositoryException e) {
log.error("Exception during repository group update: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()));
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultRepositoryGroupService method toConfig.
private RepositoryGroupConfiguration toConfig(RepositoryGroup group) {
RepositoryGroupConfiguration result = new RepositoryGroupConfiguration();
result.setId(group.getId());
result.setName(group.getName());
result.setLocation(group.getLocation());
result.setRepositories(group.getRepositories());
MergeConfiguration mergeConfig = group.getMergeConfiguration();
if (mergeConfig != null) {
result.setMergedIndexPath(mergeConfig.getMergedIndexPath());
result.setMergedIndexTtl(mergeConfig.getMergedIndexTtlMinutes());
result.setCronExpression(mergeConfig.getIndexMergeSchedule());
}
return result;
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandlerTest method putWithConfiguration.
@Test
void putWithConfiguration() throws RepositoryException {
String id = "test-group-05";
try {
RepositoryGroupHandler groupHandler = createHandler();
RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
configuration.setId(id);
configuration.setName("n-" + id);
ArrayList<String> repos = new ArrayList<>();
repos.add("internal");
configuration.setRepositories(repos);
groupHandler.put(configuration);
RepositoryGroup repo = groupHandler.get(id);
assertNotNull(repo);
assertEquals(id, repo.getId());
assertEquals("n-" + id, repo.getName());
assertNotNull(repo.getRepositories());
assertEquals(1, repo.getRepositories().size());
assertEquals("internal", repo.getRepositories().get(0).getId());
assertTrue(hasGroupInConfig(id));
} finally {
removeGroupFromConfig(id);
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandlerTest method removeWithoutSave.
@Test
void removeWithoutSave() throws RepositoryException {
RepositoryGroupHandler groupHandler = createHandler();
Configuration aCfg = new Configuration();
RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
final String id = "test-group-09";
configuration.setId(id);
configuration.setName("n-" + id);
ArrayList<String> repos = new ArrayList<>();
repos.add("internal");
configuration.setRepositories(repos);
groupHandler.put(configuration, aCfg);
assertTrue(aCfg.getRepositoryGroups().stream().anyMatch(g -> g != null && id.equals(g.getId())));
groupHandler.remove(id, aCfg);
assertNull(groupHandler.get(id));
assertTrue(aCfg.getRepositoryGroups().stream().noneMatch(g -> g != null && id.equals(g.getId())));
assertNull(groupHandler.get(id));
}
Aggregations