Search in sources :

Example 1 with EntityExistsException

use of org.apache.archiva.admin.model.EntityExistsException 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)

Example 2 with EntityExistsException

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

the class DefaultRepositoryGroupAdmin method addRepositoryToGroup.

@Override
public Boolean addRepositoryToGroup(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 add repository to it", repositoryGroupId);
    }
    if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
        throw RepositoryAdminException.ofKey("repository_group.not_editable", repositoryGroupId);
    }
    EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
    if (editableRepositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
        throw new EntityExistsException("Repository group with id " + repositoryGroupId + " already contain repository with id" + repositoryId);
    }
    org.apache.archiva.repository.ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repositoryId);
    if (managedRepo == null) {
        throw EntityNotFoundException.ofMessage("Repository with id " + repositoryId + " does not exist", repositoryId);
    }
    editableRepositoryGroup.addRepository(managedRepo);
    try {
        repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
    } catch (RepositoryException e) {
        throw new RepositoryAdminException("Could not store the repository group " + repositoryGroupId, e);
    }
    triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.ADD_REPO_TO_GROUP, auditInformation);
    return Boolean.TRUE;
}
Also used : RepositoryException(org.apache.archiva.repository.RepositoryException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) EntityExistsException(org.apache.archiva.admin.model.EntityExistsException)

Aggregations

EntityExistsException (org.apache.archiva.admin.model.EntityExistsException)2 Matcher (java.util.regex.Matcher)1 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)1 Configuration (org.apache.archiva.configuration.model.Configuration)1 RepositoryGroupConfiguration (org.apache.archiva.configuration.model.RepositoryGroupConfiguration)1 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)1 RepositoryException (org.apache.archiva.repository.RepositoryException)1