Search in sources :

Example 1 with ValidationError

use of org.apache.archiva.repository.validation.ValidationError 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()));
    }
}
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)

Example 2 with ValidationError

use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.

the class RepositoryGroupHandlerTest method validateRepository.

@Test
void validateRepository() throws IOException {
    RepositoryGroupHandler groupHandler = createHandler();
    final String id = "test-group-10";
    EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
    repositoryGroup.setMergedIndexTTL(5);
    CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepository(repositoryGroup);
    assertNotNull(result);
    assertEquals(0, result.getResult().size());
    repositoryGroup = createRepository(id, "n-test-group-10###");
    result = groupHandler.validateRepository(repositoryGroup);
    assertNotNull(result);
    assertEquals(2, result.getResult().size());
    assertNotNull(result.getResult().get("merged_index_ttl"));
    assertNotNull(result.getResult().get("name"));
}
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 3 with ValidationError

use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.

the class RepositoryGroupHandlerTest method validateRepositoryIfExisting.

@Test
void validateRepositoryIfExisting() throws IOException, RepositoryException {
    final String id = "test-group-11";
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
        repositoryGroup.setMergedIndexTTL(5);
        groupHandler.put(repositoryGroup);
        CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepository(repositoryGroup);
        assertNotNull(result);
        assertEquals(1, 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 4 with ValidationError

use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.

the class ManagedRepositoryHandlerTest method putWithCheck_invalid.

@Test
void putWithCheck_invalid() throws RepositoryException {
    final String id = "test-repo-07";
    final String name = "n-" + id;
    try {
        ManagedRepositoryHandler repoHandler = createHandler();
        BasicManagedRepositoryValidator checker = new BasicManagedRepositoryValidator(configurationHandler);
        checker.setRepositoryRegistry(repositoryRegistry);
        ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
        configuration.setId("");
        configuration.setName(name);
        CheckedResult<ManagedRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck(configuration, checker);
        assertNull(repoHandler.get(id));
        assertNotNull(result.getResult());
        assertNotNull(result.getResult().get("id"));
        assertEquals(2, result.getResult().get("id").size());
        assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
        assertFalse(hasRepositoryInConfig(id));
        assertFalse(hasRepositoryInConfig(""));
    } finally {
        removeRepositoryFromConfig(id);
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 5 with ValidationError

use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.

the class ManagedRepositoryHandlerTest method validateRepository.

@Test
void validateRepository() throws IOException {
    final String id = "test-repo-10";
    ManagedRepositoryHandler repoHandler = createHandler();
    EditableManagedRepository repository = createRepository(id, "n-" + id);
    CheckedResult<ManagedRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepository(repository);
    assertNotNull(result);
    assertEquals(0, result.getResult().size());
    repository = createRepository(id, "n-test-repo-10###");
    result = repoHandler.validateRepository(repository);
    assertNotNull(result);
    assertEquals(1, result.getResult().size());
    assertNotNull(result.getResult().get("name"));
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) EditableManagedRepository(org.apache.archiva.repository.EditableManagedRepository) ValidationError(org.apache.archiva.repository.validation.ValidationError) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

Map (java.util.Map)14 ValidationError (org.apache.archiva.repository.validation.ValidationError)14 Test (org.junit.jupiter.api.Test)12 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)6 EditableManagedRepository (org.apache.archiva.repository.EditableManagedRepository)4 EditableRemoteRepository (org.apache.archiva.repository.EditableRemoteRepository)4 ManagedRepository (org.apache.archiva.repository.ManagedRepository)4 RemoteRepository (org.apache.archiva.repository.RemoteRepository)4 RepositoryGroup (org.apache.archiva.repository.RepositoryGroup)4 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)3 RepositoryException (org.apache.archiva.repository.RepositoryException)2 RepositoryGroup (org.apache.archiva.rest.api.v2.model.RepositoryGroup)2 ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)2 ArrayList (java.util.ArrayList)1 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)1