Search in sources :

Example 11 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRepositoryCommonValidator method validateManagedRepository.

/**
 * validate cronExpression and location format
 *
 * @param managedRepository
 * @since 1.4-M2
 */
@Override
public void validateManagedRepository(ManagedRepository managedRepository) throws RepositoryAdminException {
    String cronExpression = managedRepository.getCronExpression();
    // FIXME : olamy can be empty to avoid scheduled scan ?
    if (StringUtils.isNotBlank(cronExpression)) {
        CronExpressionValidator validator = new CronExpressionValidator();
        if (!validator.validate(cronExpression)) {
            throw new RepositoryAdminException("Invalid cron expression.", "cronExpression");
        }
    } else {
        throw new RepositoryAdminException("Cron expression cannot be empty.");
    }
    String repoLocation = removeExpressions(managedRepository.getLocation());
    if (!GenericValidator.matchRegexp(repoLocation, ManagedRepositoryAdmin.REPOSITORY_LOCATION_VALID_EXPRESSION)) {
        throw new RepositoryAdminException("Invalid repository location. Directory must only contain alphanumeric characters, equals(=), question-marks(?), " + "exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-).", "location");
    }
}
Also used : CronExpressionValidator(org.apache.archiva.redback.components.scheduler.CronExpressionValidator) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 12 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultManagedRepositoryAdmin method deleteManagedRepository.

private Boolean deleteManagedRepository(ManagedRepositoryConfiguration repository, boolean deleteContent, Configuration config, boolean stagedOne) throws RepositoryAdminException {
    if (!stagedOne) {
        RepositorySession repositorySession = getRepositorySessionFactory().createSession();
        try {
            MetadataRepository metadataRepository = repositorySession.getRepository();
            metadataRepository.removeRepository(repository.getId());
            // invalidate cache
            namespacesCache.remove(repository.getId());
            log.debug("call repositoryStatisticsManager.deleteStatistics");
            getRepositoryStatisticsManager().deleteStatistics(metadataRepository, repository.getId());
            repositorySession.save();
        } catch (MetadataRepositoryException e) {
            // throw new RepositoryAdminException( e.getMessage(), e );
            log.warn("skip error during removing repository from MetadataRepository:{}", e.getMessage(), e);
        } finally {
            repositorySession.close();
        }
    }
    if (deleteContent) {
        // TODO could be async ? as directory can be huge
        Path dir = Paths.get(repository.getLocation());
        org.apache.archiva.common.utils.FileUtils.deleteQuietly(dir);
    }
    // olamy: copy list for reading as a unit test in webapp fail with ConcurrentModificationException
    List<ProxyConnectorConfiguration> proxyConnectors = new ArrayList<>(config.getProxyConnectors());
    for (ProxyConnectorConfiguration proxyConnector : proxyConnectors) {
        if (StringUtils.equals(proxyConnector.getSourceRepoId(), repository.getId())) {
            config.removeProxyConnector(proxyConnector);
        }
    }
    Map<String, List<String>> repoToGroupMap = config.getRepositoryToGroupMap();
    if (repoToGroupMap != null) {
        if (repoToGroupMap.containsKey(repository.getId())) {
            List<String> repoGroups = repoToGroupMap.get(repository.getId());
            for (String repoGroup : repoGroups) {
                // copy to prevent UnsupportedOperationException
                RepositoryGroupConfiguration repositoryGroupConfiguration = config.findRepositoryGroupById(repoGroup);
                List<String> repos = new ArrayList<>(repositoryGroupConfiguration.getRepositories());
                config.removeRepositoryGroup(repositoryGroupConfiguration);
                repos.remove(repository.getId());
                repositoryGroupConfiguration.setRepositories(repos);
                config.addRepositoryGroup(repositoryGroupConfiguration);
            }
        }
    }
    try {
        removeRepositoryRoles(repository);
    } catch (RoleManagerException e) {
        throw new RepositoryAdminException("fail to remove repository roles for repository " + repository.getId() + " : " + e.getMessage(), e);
    }
    try {
        final RepositoryRegistry reg = getRepositoryRegistry();
        if (reg.getManagedRepository(repository.getId()) != null) {
            reg.removeRepository(reg.getManagedRepository(repository.getId()));
        }
    } catch (RepositoryException e) {
        throw new RepositoryAdminException("Removal of repository " + repository.getId() + " failed: " + e.getMessage());
    }
    saveConfiguration(config);
    return Boolean.TRUE;
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) Path(java.nio.file.Path) RepositoryGroupConfiguration(org.apache.archiva.configuration.RepositoryGroupConfiguration) ArrayList(java.util.ArrayList) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RepositoryException(org.apache.archiva.repository.RepositoryException) MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) List(java.util.List) ArrayList(java.util.ArrayList) RoleManagerException(org.apache.archiva.redback.role.RoleManagerException)

Example 13 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultProxyConnectorAdmin method deleteProxyConnector.

// FIXME take care of proxyConnectorRules !
@Override
public Boolean deleteProxyConnector(ProxyConnector proxyConnector, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    ProxyConnectorConfiguration proxyConnectorConfiguration = findProxyConnector(proxyConnector.getSourceRepoId(), proxyConnector.getTargetRepoId(), configuration);
    if (proxyConnectorConfiguration == null) {
        throw new RepositoryAdminException("unable to find ProxyConnector with source " + proxyConnector.getSourceRepoId() + " and target " + proxyConnector.getTargetRepoId());
    }
    configuration.removeProxyConnector(proxyConnectorConfiguration);
    saveConfiguration(configuration);
    triggerAuditEvent(proxyConnector.getSourceRepoId() + "-" + proxyConnector.getTargetRepoId(), null, AuditEvent.DELETE_PROXY_CONNECTOR, auditInformation);
    return Boolean.TRUE;
}
Also used : ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ProxyConnectorConfiguration(org.apache.archiva.configuration.ProxyConnectorConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 14 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultArchivaAdministration method addFileType.

@Override
public void addFileType(FileType fileType, AuditInformation auditInformation) throws RepositoryAdminException {
    Configuration configuration = getArchivaConfiguration().getConfiguration();
    if (getFileTypeById(fileType.getId(), configuration) != null) {
        throw new RepositoryAdminException("impossible to FileType with id " + fileType.getId() + " already exists");
    }
    configuration.getRepositoryScanning().addFileType(getModelMapper().map(fileType, org.apache.archiva.configuration.FileType.class));
    saveConfiguration(configuration);
}
Also used : UiConfiguration(org.apache.archiva.admin.model.beans.UiConfiguration) NetworkConfiguration(org.apache.archiva.admin.model.beans.NetworkConfiguration) Configuration(org.apache.archiva.configuration.Configuration) WebappConfiguration(org.apache.archiva.configuration.WebappConfiguration) FileType(org.apache.archiva.admin.model.beans.FileType) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 15 with RepositoryAdminException

use of org.apache.archiva.admin.model.RepositoryAdminException in project archiva by apache.

the class DefaultRepositoryGroupAdmin method deleteRepositoryFromGroup.

@Override
public Boolean deleteRepositoryFromGroup(String repositoryGroupId, String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
    RepositoryGroup repositoryGroup = getRepositoryGroup(repositoryGroupId);
    if (repositoryGroup == null) {
        throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not exists so cannot remove repository from it");
    }
    if (!repositoryGroup.getRepositories().contains(repositoryId)) {
        throw new RepositoryAdminException("repositoryGroup with id " + repositoryGroupId + " doesn't not contains repository with id" + repositoryId);
    }
    repositoryGroup.removeRepository(repositoryId);
    updateRepositoryGroup(repositoryGroup, auditInformation, false);
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.DELETE_REPO_FROM_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryGroup(org.apache.archiva.admin.model.beans.RepositoryGroup) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)67 Configuration (org.apache.archiva.configuration.Configuration)18 Path (java.nio.file.Path)15 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)14 ArchivaRestServiceException (org.apache.archiva.rest.api.services.ArchivaRestServiceException)14 RepositoryException (org.apache.archiva.repository.RepositoryException)13 IOException (java.io.IOException)12 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)10 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)10 ArrayList (java.util.ArrayList)9 RepositoryGroupConfiguration (org.apache.archiva.configuration.RepositoryGroupConfiguration)7 NetworkProxy (org.apache.archiva.admin.model.beans.NetworkProxy)6 ProxyConnectorConfiguration (org.apache.archiva.configuration.ProxyConnectorConfiguration)6 IndexUpdateFailedException (org.apache.archiva.indexer.IndexUpdateFailedException)6 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)6 RemoteRepository (org.apache.archiva.repository.RemoteRepository)6 Date (java.util.Date)5 RemoteIndexFeature (org.apache.archiva.repository.features.RemoteIndexFeature)5 PostConstruct (javax.annotation.PostConstruct)4 LdapGroupMapping (org.apache.archiva.admin.model.beans.LdapGroupMapping)4