Search in sources :

Example 11 with EditableRepositoryGroup

use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.

the class BasicRepositoryGroupValidatorTest method applyWithEmptyId.

@Test
void applyWithEmptyId() throws IOException {
    BasicRepositoryGroupValidator validator = new BasicRepositoryGroupValidator(configurationHandler);
    EditableRepositoryGroup group = createGroup("", "test");
    group.setMergedIndexTTL(0);
    ValidationResponse<RepositoryGroup> result = validator.apply(group);
    assertNotNull(result);
    assertFalse(result.isValid());
    assertTrue(result.getResult().containsKey("id"));
    assertEquals("repository_group", result.getResult().get("id").get(0).getCategory());
    assertEquals("empty", result.getResult().get("id").get(0).getType());
    assertEquals("id", result.getResult().get("id").get(0).getAttribute());
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Test(org.junit.jupiter.api.Test)

Example 12 with EditableRepositoryGroup

use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.

the class BasicRepositoryGroupValidatorTest method applyWithBadTTL.

@Test
void applyWithBadTTL() throws IOException {
    BasicRepositoryGroupValidator validator = new BasicRepositoryGroupValidator(configurationHandler);
    EditableRepositoryGroup group = createGroup("test", "test");
    group.setMergedIndexTTL(0);
    ValidationResponse<RepositoryGroup> result = validator.apply(group);
    assertNotNull(result);
    assertFalse(result.isValid());
    assertTrue(result.getResult().containsKey("merged_index_ttl"));
    assertEquals("repository_group", result.getResult().get("merged_index_ttl").get(0).getCategory());
    assertEquals("min", result.getResult().get("merged_index_ttl").get(0).getType());
    assertEquals("merged_index_ttl", result.getResult().get("merged_index_ttl").get(0).getAttribute());
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Test(org.junit.jupiter.api.Test)

Example 13 with EditableRepositoryGroup

use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.

the class MavenRepositoryProviderTest method createRepositoryGroup.

@Test
public void createRepositoryGroup() {
    EditableRepositoryGroup gr = provider.createRepositoryGroup("group1", "Group 1");
    assertEquals("group1", gr.getId());
    assertEquals("Group 1", gr.getName());
    assertEquals(MavenRepositoryGroup.class, gr.getClass());
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Test(org.junit.Test)

Example 14 with EditableRepositoryGroup

use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.

the class RepositoryGroupHandlerTest method validateRepositoryForUpdate.

@Test
void validateRepositoryForUpdate() throws IOException, RepositoryException {
    final String id = "test-group-12";
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
        repositoryGroup.setMergedIndexTTL(5);
        groupHandler.put(repositoryGroup);
        CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepositoryForUpdate(repositoryGroup);
        assertNotNull(result);
        assertEquals(0, result.getResult().size());
    } finally {
        removeGroupFromConfig(id);
    }
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.repository.RepositoryGroup) ValidationError(org.apache.archiva.repository.validation.ValidationError) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 15 with EditableRepositoryGroup

use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.

the class DefaultRepositoryGroupService method deleteRepositoryFromGroup.

@Override
public RepositoryGroup deleteRepositoryFromGroup(final String repositoryGroupId, final String repositoryId) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, repositoryGroupId), 404);
    }
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId), 404);
    }
    try {
        org.apache.archiva.repository.RepositoryGroup repositoryGroup = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
        if (repositoryGroup == null) {
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
        }
        if (repositoryGroup.getRepositories().stream().noneMatch(r -> repositoryId.equals(r.getId()))) {
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId), 404);
        }
        if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
            log.error("This group instance is not editable: {}", repositoryGroupId);
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, ""), 500);
        }
        EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
        editableRepositoryGroup.removeRepository(repositoryId);
        org.apache.archiva.repository.RepositoryGroup newGroup = repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
        return RepositoryGroup.of(newGroup);
    } catch (RepositoryException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()), 500);
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RepositoryException(org.apache.archiva.repository.RepositoryException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Aggregations

EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)19 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)12 Test (org.junit.jupiter.api.Test)11 RepositoryException (org.apache.archiva.repository.RepositoryException)6 Map (java.util.Map)4 ValidationError (org.apache.archiva.repository.validation.ValidationError)3 EntityExistsException (org.apache.archiva.admin.model.EntityExistsException)2 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)2 Configuration (org.apache.archiva.configuration.model.Configuration)2 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)2 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)2 RepositoryType (org.apache.archiva.repository.RepositoryType)2 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1