Search in sources :

Example 71 with Configuration

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

the class DefaultArchivaAdministration method addFileTypePattern.

@Override
public void addFileTypePattern(String fileTypeId, String pattern, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    org.apache.archiva.configuration.model.FileType fileType = getFileTypeById(fileTypeId, configuration);
    if (fileType == null) {
        return;
    }
    if (fileType.getPatterns().contains(pattern)) {
        throw new RepositoryAdminException("File type [" + fileTypeId + "] already contains pattern [" + pattern + "]");
    }
    fileType.addPattern(pattern);
    saveConfiguration(configuration);
    triggerAuditEvent("", "", AuditEvent.ADD_PATTERN, auditInformation);
}
Also used : WebappConfiguration(org.apache.archiva.configuration.model.WebappConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 72 with Configuration

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

the class DefaultManagedRepositoryAdmin method addManagedRepository.

@Override
public Boolean addManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation) throws RepositoryAdminException {
    log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
    getRepositoryCommonValidator().basicValidation(managedRepository, false);
    getRepositoryCommonValidator().validateManagedRepository(managedRepository);
    triggerAuditEvent(managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
    ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration(managedRepository);
    if (needStageRepo) {
        repoConfig.setStageRepoNeeded(true);
    }
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    try {
        org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository(repoConfig);
        log.debug("Added new repository {}", newRepo.getId());
        addRepositoryRoles(newRepo.getId());
        // scan repository when adding of repository is successful
        try {
            if (newRepo.isScanned()) {
                scanRepository(newRepo.getId(), true);
            }
            org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
            if (stagingRepo != null) {
                if (stagingRepo.isScanned()) {
                    scanRepository(stagingRepo.getId(), true);
                }
                addRepositoryRoles(stagingRepo.getId());
            }
        } catch (Exception e) {
            log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
        }
    } catch (RepositoryException e) {
        log.error("Could not add managed repository {}" + managedRepository);
        throw new RepositoryAdminException("Could not add repository " + e.getMessage());
    } catch (RoleManagerException e) {
        log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
        throw new RepositoryAdminException("Could not add roles to repository " + e.getMessage());
    }
    return Boolean.TRUE;
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) StagingRepositoryFeature(org.apache.archiva.repository.features.StagingRepositoryFeature) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) TaskQueueException(org.apache.archiva.components.taskqueue.TaskQueueException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 73 with Configuration

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

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

@Override
public Boolean deleteManagedRepository(String repositoryId, AuditInformation auditInformation, boolean deleteContent) throws RepositoryAdminException {
    Configuration config = getArchivaConfiguration().getConfiguration();
    ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById(repositoryId);
    if (repoConfig != null) {
        log.debug("Repo location " + repoConfig.getLocation());
        org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
        org.apache.archiva.repository.ManagedRepository stagingRepository = null;
        if (repo != null) {
            if (repo.supportsFeature(StagingRepositoryFeature.class)) {
                stagingRepository = repo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
            }
        } else {
            throw new RepositoryAdminException("A repository with that id does not exist");
        }
        triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
        if (repoConfig != null) {
            deleteManagedRepository(repoConfig, deleteContent, config, false);
        }
        // stage repo exists ?
        if (stagingRepository != null) {
            // do not trigger event when deleting the staged one
            ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
            if (stagingRepositoryConfig != null) {
                deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
            }
        }
        try {
            saveConfiguration(config);
        } catch (Exception e) {
            throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
        }
        return Boolean.TRUE;
    } else {
        return Boolean.FALSE;
    }
}
Also used : ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) ProxyConnectorConfiguration(org.apache.archiva.configuration.model.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.model.ManagedRepositoryConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataSessionException(org.apache.archiva.metadata.repository.MetadataSessionException) IOException(java.io.IOException) IndexUpdateFailedException(org.apache.archiva.indexer.IndexUpdateFailedException) TaskQueueException(org.apache.archiva.components.taskqueue.TaskQueueException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException)

Example 74 with Configuration

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

the class DefaultRepositoryGroupAdmin method updateRepositoryGroup.

private Boolean updateRepositoryGroup(RepositoryGroup repositoryGroup, AuditInformation auditInformation, boolean triggerAuditEvent) throws RepositoryAdminException {
    validateRepositoryGroup(repositoryGroup, true);
    validateManagedRepositoriesExists(repositoryGroup.getRepositories());
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    RepositoryGroupConfiguration repositoryGroupConfiguration = configuration.getRepositoryGroupsAsMap().get(repositoryGroup.getId());
    repositoryGroupConfiguration.setRepositories(repositoryGroup.getRepositories());
    repositoryGroupConfiguration.setMergedIndexPath(repositoryGroup.getMergedIndexPath());
    repositoryGroupConfiguration.setMergedIndexTtl(repositoryGroup.getMergedIndexTtl());
    repositoryGroupConfiguration.setCronExpression(repositoryGroup.getCronExpression());
    try {
        repositoryRegistry.putRepositoryGroup(repositoryGroupConfiguration);
    } catch (RepositoryException e) {
        log.error("Could not update the repository group in the registry: {}", e.getMessage(), e);
        throw RepositoryAdminException.ofKey("repository_group.registry.update_error", e, repositoryGroup.getId(), e.getMessage());
    }
    org.apache.archiva.repository.RepositoryGroup rg = repositoryRegistry.getRepositoryGroup(repositoryGroup.getId());
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) RepositoryException(org.apache.archiva.repository.RepositoryException)

Example 75 with Configuration

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

the class DefaultRepositoryGroupAdmin method validateRepositoryGroup.

public Boolean validateRepositoryGroup(RepositoryGroup repositoryGroup, boolean updateMode) throws RepositoryAdminException {
    String repoGroupId = repositoryGroup.getId();
    if (StringUtils.isBlank(repoGroupId)) {
        throw RepositoryAdminException.ofKey("repository_group.id.empty");
    }
    if (repoGroupId.length() > 100) {
        throw RepositoryAdminException.ofKey("repository_group.id.max_length", repoGroupId, Integer.toString(100));
    }
    Matcher matcher = REPO_GROUP_ID_PATTERN.matcher(repoGroupId);
    if (!matcher.matches()) {
        throw RepositoryAdminException.ofKey("repository_group.id.invalid_chars", "alphanumeric, '.', '-','_'");
    }
    if (repositoryGroup.getMergedIndexTtl() <= 0) {
        throw RepositoryAdminException.ofKey("repository_group.merged_index_ttl.min", "0");
    }
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    if (configuration.getRepositoryGroupsAsMap().containsKey(repoGroupId)) {
        if (!updateMode) {
            throw new EntityExistsException("Unable to add new repository group with id [" + repoGroupId + "], that id already exists as a repository group.");
        }
    } else if (configuration.getManagedRepositoriesAsMap().containsKey(repoGroupId)) {
        throw new EntityExistsException("Unable to add new repository group with id [" + repoGroupId + "], that id already exists as a managed repository.");
    } else if (configuration.getRemoteRepositoriesAsMap().containsKey(repoGroupId)) {
        throw new EntityExistsException("Unable to add new repository group with id [" + repoGroupId + "], that id already exists as a remote repository.");
    }
    return Boolean.TRUE;
}
Also used : RepositoryGroupConfiguration(org.apache.archiva.configuration.model.RepositoryGroupConfiguration) Configuration(org.apache.archiva.configuration.model.Configuration) Matcher(java.util.regex.Matcher) EntityExistsException(org.apache.archiva.admin.model.EntityExistsException)

Aggregations

Configuration (org.apache.archiva.configuration.model.Configuration)94 ManagedRepositoryConfiguration (org.apache.archiva.configuration.model.ManagedRepositoryConfiguration)56 ContextConfiguration (org.springframework.test.context.ContextConfiguration)45 RemoteRepositoryConfiguration (org.apache.archiva.configuration.model.RemoteRepositoryConfiguration)42 ProxyConnectorConfiguration (org.apache.archiva.configuration.model.ProxyConnectorConfiguration)34 ArchivaConfiguration (org.apache.archiva.configuration.provider.ArchivaConfiguration)34 WebappConfiguration (org.apache.archiva.configuration.model.WebappConfiguration)32 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)29 Path (java.nio.file.Path)27 Test (org.junit.Test)26 NetworkProxyConfiguration (org.apache.archiva.configuration.model.NetworkProxyConfiguration)23 RepositoryScanningConfiguration (org.apache.archiva.configuration.model.RepositoryScanningConfiguration)23 RepositoryException (org.apache.archiva.repository.RepositoryException)22 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)14 ManagedRepository (org.apache.archiva.repository.ManagedRepository)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 RemoteRepository (org.apache.archiva.repository.RemoteRepository)12 Test (org.junit.jupiter.api.Test)12 LegacyArtifactPath (org.apache.archiva.configuration.model.LegacyArtifactPath)11