Search in sources :

Example 16 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.

the class RepositoryGroupHandlerTest method removeGroupFromConfig.

// Helper method that removes a group from the configuration
private void removeGroupFromConfig(String groupId) {
    Configuration configuration = configurationHandler.getBaseConfiguration();
    Iterator<RepositoryGroupConfiguration> groupIter = configuration.getRepositoryGroups().iterator();
    while (groupIter.hasNext()) {
        RepositoryGroupConfiguration group = groupIter.next();
        if (groupId.equals(group.getId())) {
            groupIter.remove();
            break;
        }
    }
    try {
        configurationHandler.save(configuration);
    } catch (Throwable e) {
        System.err.println("Could not remove repo group from config " + groupId);
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration)

Example 17 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.

the class RepositoryGroupHandlerTest method testPutWithoutRegister.

@Test
void testPutWithoutRegister() throws RepositoryException {
    RepositoryGroupHandler groupHandler = createHandler();
    Configuration aCfg = new Configuration();
    RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
    final String id = "test-group-06";
    configuration.setId(id);
    configuration.setName("n-" + id);
    ArrayList<String> repos = new ArrayList<>();
    repos.add("internal");
    configuration.setRepositories(repos);
    groupHandler.put(configuration, aCfg);
    RepositoryGroup repo = groupHandler.get(id);
    assertNull(repo);
    assertFalse(hasGroupInConfig(id));
    assertTrue(aCfg.getRepositoryGroups().stream().anyMatch(g -> g != null && id.equals(g.getId())));
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ArgumentMatchers(org.mockito.ArgumentMatchers) CheckedResult(org.apache.archiva.repository.validation.CheckedResult) Mock(org.mockito.Mock) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) FilesystemStorage(org.apache.archiva.repository.storage.fs.FilesystemStorage) ArchivaRepositoryRegistry(org.apache.archiva.repository.base.ArchivaRepositoryRegistry) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) RemoteRepository(org.apache.archiva.repository.RemoteRepository) RepositoryHandler(org.apache.archiva.repository.RepositoryHandler) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ISEMPTY(org.apache.archiva.repository.validation.ErrorKeys.ISEMPTY) Map(java.util.Map) FileUtils(org.apache.archiva.common.utils.FileUtils) Named(javax.inject.Named) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) ConfigurationHandler(org.apache.archiva.repository.base.ConfigurationHandler) ValidationError(org.apache.archiva.repository.validation.ValidationError) Path(java.nio.file.Path) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Iterator(java.util.Iterator) SpringExtension(org.springframework.test.context.junit.jupiter.SpringExtension) Files(java.nio.file.Files) FileLockManager(org.apache.archiva.common.filelock.FileLockManager) RepositoryException(org.apache.archiva.repository.RepositoryException) MergedRemoteIndexesScheduler(org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) IOException(java.io.IOException) RepositoryType(org.apache.archiva.repository.RepositoryType) ManagedRepository(org.apache.archiva.repository.ManagedRepository) Mockito.verify(org.mockito.Mockito.verify) BasicRemoteRepository(org.apache.archiva.repository.base.remote.BasicRemoteRepository) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Paths(java.nio.file.Paths) ContextConfiguration(org.springframework.test.context.ContextConfiguration) DefaultFileLockManager(org.apache.archiva.common.filelock.DefaultFileLockManager) Assertions(org.junit.jupiter.api.Assertions) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) RepositoryState(org.apache.archiva.repository.RepositoryState) BasicManagedRepository(org.apache.archiva.repository.base.managed.BasicManagedRepository) ArchivaConfiguration(org.apache.archiva.configuration.provider.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RemoteRepositoryConfiguration(org.apache.archiva.configuration.model.RemoteRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 18 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.

the class RepositoryGroupHandlerTest method remove.

@Test
void remove() throws RepositoryException {
    RepositoryGroupHandler groupHandler = createHandler();
    RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
    final String id = "test-group-08";
    configuration.setId(id);
    configuration.setName("n-" + id);
    groupHandler.put(configuration);
    assertTrue(hasGroupInConfig(id));
    assertNotNull(groupHandler.get(id));
    groupHandler.remove(id);
    assertNull(groupHandler.get(id));
    assertFalse(hasGroupInConfig(id));
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Test(org.junit.jupiter.api.Test)

Example 19 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.

the class RepositoryGroupHandlerTest method putWithCheck_invalid.

@Test
void putWithCheck_invalid() throws RepositoryException {
    final String id = "test-group-07";
    final String name = "n-" + id;
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        BasicRepositoryGroupValidator checker = new BasicRepositoryGroupValidator(configurationHandler);
        RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
        configuration.setId("");
        configuration.setName(name);
        ArrayList<String> repos = new ArrayList<>();
        repos.add("internal");
        configuration.setRepositories(repos);
        CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.putWithCheck(configuration, checker);
        assertNull(groupHandler.get(id));
        assertNotNull(result.getResult());
        assertNotNull(result.getResult().get("id"));
        assertEquals(1, result.getResult().get("id").size());
        assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
        assertFalse(hasGroupInConfig(id));
        assertFalse(hasGroupInConfig(""));
    } finally {
        removeGroupFromConfig(id);
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ArrayList(java.util.ArrayList) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 20 with RepositoryGroupConfiguration

use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.

the class DefaultRepositoryGroupService method addRepositoryGroup.

@Override
public RepositoryGroup addRepositoryGroup(RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
    final String groupId = repositoryGroup.getId();
    if (StringUtils.isEmpty(groupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, groupId), 422);
    }
    if (repositoryRegistry.hasRepositoryGroup(groupId)) {
        httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(groupId).build().toString());
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, groupId), 303);
    }
    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) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_ADD_FAILED));
    }
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map)

Aggregations

RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)28 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)11 RepositoryException (org.apache.archiva.repository.RepositoryException)10 Configuration (org.apache.archiva.configuration.model.Configuration)9 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)9 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)9 ArrayList (java.util.ArrayList)8 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)7 Map (java.util.Map)5 ValidationError (org.apache.archiva.repository.validation.ValidationError)5 Test (org.junit.Test)5 Test (org.junit.jupiter.api.Test)5 ContextConfiguration (org.springframework.test.context.ContextConfiguration)5 IOException (java.io.IOException)4 Iterator (java.util.Iterator)4 List (java.util.List)4 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)4 RepositoryProvider (org.apache.archiva.repository.RepositoryProvider)4 RepositoryType (org.apache.archiva.repository.RepositoryType)4 Path (java.nio.file.Path)3