use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class DefaultProxyConnectorRuleAdmin method addProxyConnectorRule.
@Override
public void addProxyConnectorRule(ProxyConnectorRule proxyConnectorRule, AuditInformation auditInformation) throws RepositoryAdminException {
ProxyConnectorRuleConfiguration proxyConnectorRuleConfiguration = new ProxyConnectorRuleConfiguration();
proxyConnectorRuleConfiguration.setPattern(proxyConnectorRule.getPattern());
proxyConnectorRuleConfiguration.setRuleType(proxyConnectorRule.getProxyConnectorRuleType().getRuleType());
for (ProxyConnector proxyConnector : proxyConnectorRule.getProxyConnectors()) {
ProxyConnectorConfiguration proxyConnectorConfiguration = new ProxyConnectorConfiguration();
proxyConnectorConfiguration.setSourceRepoId(proxyConnector.getSourceRepoId());
proxyConnectorConfiguration.setTargetRepoId(proxyConnector.getTargetRepoId());
proxyConnectorRuleConfiguration.getProxyConnectors().add(proxyConnectorConfiguration);
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
configuration.getProxyConnectorRuleConfigurations().add(proxyConnectorRuleConfiguration);
saveConfiguration(configuration);
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class DefaultRepositoryCommonValidator method basicValidation.
/**
* @param abstractRepository
* @param update in update mode if yes already exists won't be check
* @throws RepositoryAdminException
*/
@Override
public void basicValidation(AbstractRepository abstractRepository, boolean update) throws RepositoryAdminException {
Configuration config = archivaConfiguration.getConfiguration();
String repoId = abstractRepository.getId();
if (!update) {
if (config.getManagedRepositoriesAsMap().containsKey(repoId)) {
throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a managed repository.");
} else if (config.getRepositoryGroupsAsMap().containsKey(repoId)) {
throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a repository group.");
} else if (config.getRemoteRepositoriesAsMap().containsKey(repoId)) {
throw new RepositoryAdminException("Unable to add new repository with id [" + repoId + "], that id already exists as a remote repository.");
}
}
if (StringUtils.isBlank(repoId)) {
throw new RepositoryAdminException("Repository ID cannot be empty.");
}
if (!REPOSITORY_ID_VALID_EXPRESSION_PATTERN.matcher(repoId).matches()) {
throw new RepositoryAdminException("Invalid repository ID. Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-).");
}
String name = abstractRepository.getName();
if (StringUtils.isBlank(name)) {
throw new RepositoryAdminException("repository name cannot be empty");
}
if (!REPOSITORY_NAME_VALID_EXPRESSION_PATTERN.matcher(name).matches()) {
throw new RepositoryAdminException("Invalid repository name. Repository Name must only contain alphanumeric characters, white-spaces(' '), " + "forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-).");
}
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ArchivaRepositoryRegistryTest method putManagedRepositoryFromConfigWithoutSave.
@Test
public void putManagedRepositoryFromConfigWithoutSave() throws Exception {
Configuration configuration = archivaConfiguration.getConfiguration();
int actualSize = configuration.getManagedRepositories().size();
Configuration newConfiguration = new Configuration();
ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
cfg.setId("test002");
cfg.setName("This is test 002");
ManagedRepository repo = repositoryRegistry.putRepository(cfg, newConfiguration);
assertNotNull(repo);
assertEquals("test002", repo.getId());
assertEquals("This is test 002", repo.getName());
assertNotNull(repo.getContent());
archivaConfiguration.reload();
assertEquals(actualSize, configuration.getManagedRepositories().size());
List<ManagedRepositoryConfiguration> repos = newConfiguration.getManagedRepositories();
assertEquals(1, repos.size());
ManagedRepository internalRepo = repositoryRegistry.getManagedRepository("internal");
cfg = new ManagedRepositoryConfiguration();
cfg.setId("internal");
cfg.setName("This is internal test 002");
repo = repositoryRegistry.putRepository(cfg, newConfiguration);
assertEquals("This is internal test 002", repo.getName());
assertEquals(2, newConfiguration.getManagedRepositories().size());
repositoryRegistry.reload();
assertEquals(actualSize, configuration.getManagedRepositories().size());
}
use of org.apache.archiva.configuration.model.Configuration 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));
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class ManagedRepositoryHandlerTest method removeWithoutSave.
@Test
void removeWithoutSave() throws RepositoryException {
final String id = "test-repo-09";
ManagedRepositoryHandler repoHandler = createHandler();
Configuration aCfg = new Configuration();
ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
configuration.setId(id);
configuration.setName("n-" + id);
repoHandler.put(configuration, aCfg);
assertTrue(aCfg.getManagedRepositories().stream().anyMatch(g -> g != null && id.equals(g.getId())));
repoHandler.remove(id, aCfg);
assertNull(repoHandler.get(id));
assertTrue(aCfg.getManagedRepositories().stream().noneMatch(g -> g != null && id.equals(g.getId())));
assertNull(repoHandler.get(id));
}
Aggregations