Search in sources :

Example 1 with EditableRepositoryGroup

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

the class RepositoryGroupHandler method updateReferences.

@Override
public void updateReferences(RepositoryGroup repo, RepositoryGroupConfiguration repositoryConfiguration) {
    if (repo instanceof EditableRepositoryGroup && repositoryConfiguration != null) {
        EditableRepositoryGroup eGroup = (EditableRepositoryGroup) repo;
        RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration> managedHandler = repositoryRegistry.getHandler(ManagedRepository.class, ManagedRepositoryConfiguration.class);
        eGroup.setRepositories(repositoryConfiguration.getRepositories().stream().map(managedHandler::get).collect(Collectors.toList()));
    }
}
Also used : ManagedRepository(org.apache.archiva.repository.ManagedRepository) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 2 with EditableRepositoryGroup

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

the class DefaultRepositoryGroupAdmin method deleteRepositoryFromGroup.

@Override
public Boolean deleteRepositoryFromGroup(String repositoryGroupId, String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
    org.apache.archiva.repository.RepositoryGroup repositoryGroup = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
    if (repositoryGroup == null) {
        throw EntityNotFoundException.ofMessage("Repository group with id " + repositoryGroupId + " doesn't not exists so cannot remove repository from it", repositoryGroupId);
    }
    if (!repositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
        throw EntityNotFoundException.ofMessage("repositoryGroup with id " + repositoryGroupId + " doesn't not contains repository with id" + repositoryId, repositoryId);
    }
    if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
        throw RepositoryAdminException.ofKey("repository_group.not_editable", repositoryGroupId);
    }
    EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
    editableRepositoryGroup.removeRepository(repositoryId);
    try {
        repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
    } catch (RepositoryException e) {
        throw new RepositoryAdminException("Could not store repository group " + repositoryGroupId, e);
    }
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.DELETE_REPO_FROM_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryGroupAdmin(org.apache.archiva.admin.model.group.RepositoryGroupAdmin) AuditInformation(org.apache.archiva.admin.model.AuditInformation) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) StorageAsset(org.apache.archiva.repository.storage.StorageAsset) LoggerFactory(org.slf4j.LoggerFactory) EntityNotFoundException(org.apache.archiva.admin.model.EntityNotFoundException) EventHandler(org.apache.archiva.event.EventHandler) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Matcher(java.util.regex.Matcher) EntityExistsException(org.apache.archiva.admin.model.EntityExistsException) Service(org.springframework.stereotype.Service) Map(java.util.Map) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryRegistryEvent(org.apache.archiva.repository.event.RepositoryRegistryEvent) Logger(org.slf4j.Logger) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) IndexCreationFeature(org.apache.archiva.repository.features.IndexCreationFeature) AbstractRepositoryAdmin(org.apache.archiva.admin.repository.AbstractRepositoryAdmin) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) Event(org.apache.archiva.event.Event) Collectors(java.util.stream.Collectors) AuditEvent(org.apache.archiva.metadata.model.facets.AuditEvent) List(java.util.List) EventType(org.apache.archiva.event.EventType) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) PostConstruct(javax.annotation.PostConstruct) Pattern(java.util.regex.Pattern) RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup)

Example 3 with EditableRepositoryGroup

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

the class DefaultRepositoryGroupService method addRepositoryToGroup.

@Override
public RepositoryGroup addRepositoryToGroup(String repositoryGroupId, String repositoryId) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
    }
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 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 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;
        if (editableRepositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
            log.info("Repository {} is already member of group {}", repositoryId, repositoryGroupId);
            return RepositoryGroup.of(editableRepositoryGroup);
        }
        org.apache.archiva.repository.ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repositoryId);
        if (managedRepo == null) {
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
        }
        editableRepositoryGroup.addRepository(managedRepo);
        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)

Example 4 with EditableRepositoryGroup

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

the class RepositoryGroupHandlerTest method put.

@Test
void put() throws IOException, RepositoryException {
    final String id = "test-group-04";
    try {
        RepositoryGroupHandler groupHandler = createHandler();
        EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
        groupHandler.put(repositoryGroup);
        RepositoryGroup storedGroup = groupHandler.get(id);
        assertNotNull(storedGroup);
        assertEquals(id, storedGroup.getId());
        assertEquals("n-" + id, storedGroup.getName());
        EditableRepositoryGroup repositoryGroup2 = createRepository(id, "n2-" + id);
        groupHandler.put(repositoryGroup2);
        storedGroup = groupHandler.get(id);
        assertNotNull(storedGroup);
        assertEquals(id, storedGroup.getId());
        assertEquals("n2-" + id, storedGroup.getName());
        assertTrue(hasGroupInConfig(id));
    } finally {
        removeGroupFromConfig(id);
    }
}
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 5 with EditableRepositoryGroup

use of org.apache.archiva.repository.EditableRepositoryGroup 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)

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