Search in sources :

Example 16 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.

the class DefaultRepositoryGroupService method getRepositoriesGroups.

@Override
public PagedResult<RepositoryGroup> getRepositoriesGroups(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order) throws ArchivaRestServiceException {
    try {
        Predicate<org.apache.archiva.repository.RepositoryGroup> filter = QUERY_HELPER.getQueryFilter(searchTerm);
        Comparator<org.apache.archiva.repository.RepositoryGroup> ordering = QUERY_HELPER.getComparator(orderBy, QUERY_HELPER.isAscending(order));
        int totalCount = Math.toIntExact(repositoryRegistry.getRepositoryGroups().stream().filter(filter).count());
        List<RepositoryGroup> result = repositoryRegistry.getRepositoryGroups().stream().filter(filter).sorted(ordering).skip(offset).limit(limit).map(RepositoryGroup::of).collect(Collectors.toList());
        return new PagedResult<>(totalCount, offset, limit, result);
    } catch (ArithmeticException e) {
        log.error("Could not convert total count: {}", e.getMessage());
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
    }
}
Also used : EditableRepositoryGroup(org.apache.archiva.repository.EditableRepositoryGroup) RepositoryGroup(org.apache.archiva.rest.api.v2.model.RepositoryGroup) ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) PagedResult(org.apache.archiva.components.rest.model.PagedResult)

Example 17 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.

the class DefaultRepositoryGroupService method addRepositoryGroup.

@Override
public RepositoryGroup addRepositoryGroup(RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
    final String groupId = repositoryGroup.getId();
    if (StringUtils.isEmpty(groupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, groupId), 422);
    }
    if (repositoryRegistry.hasRepositoryGroup(groupId)) {
        httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(groupId).build().toString());
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, groupId), 303);
    }
    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) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_ADD_FAILED));
    }
}
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 18 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.

the class DefaultRepositoryGroupService method deleteRepositoryFromGroup.

@Override
public RepositoryGroup deleteRepositoryFromGroup(final String repositoryGroupId, final String repositoryId) throws ArchivaRestServiceException {
    if (StringUtils.isEmpty(repositoryGroupId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, repositoryGroupId), 404);
    }
    if (StringUtils.isEmpty(repositoryId)) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId), 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.getRepositories().stream().noneMatch(r -> repositoryId.equals(r.getId()))) {
            throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId), 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;
        editableRepositoryGroup.removeRepository(repositoryId);
        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 19 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.

the class DefaultSecurityConfigurationService method updateLdapConfiguration.

@Override
public LdapConfiguration updateLdapConfiguration(LdapConfiguration configuration) throws ArchivaRestServiceException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        updateConfig(configuration, redbackRuntimeConfiguration);
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        ldapConnectionFactory.initialize();
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
    try {
        return LdapConfiguration.of(redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration().getLdapConfiguration());
    } catch (RepositoryAdminException e) {
        log.error("Error while retrieve updated configuration: {}", e.getMessage());
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR, e.getMessage()));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 20 with ArchivaRestServiceException

use of org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException in project archiva by apache.

the class DefaultSecurityConfigurationService method updateCacheConfiguration.

@Override
public CacheConfiguration updateCacheConfiguration(CacheConfiguration cacheConfiguration) throws ArchivaRestServiceException {
    if (cacheConfiguration == null) {
        throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.MISSING_DATA), 400);
    }
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        log.debug("getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration);
        updateConfig(cacheConfiguration, redbackRuntimeConfiguration);
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
        return getCacheConfiguration();
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(ErrorMessage.of(REPOSITORY_ADMIN_ERROR));
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Aggregations

ArchivaRestServiceException (org.apache.archiva.rest.api.v2.svc.ArchivaRestServiceException)23 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)9 RedbackRuntimeConfiguration (org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration)8 RepositoryException (org.apache.archiva.repository.RepositoryException)6 Map (java.util.Map)4 PagedResult (org.apache.archiva.components.rest.model.PagedResult)4 AuthenticationException (javax.naming.AuthenticationException)3 AuthenticationNotSupportedException (javax.naming.AuthenticationNotSupportedException)3 CommunicationException (javax.naming.CommunicationException)3 InvalidNameException (javax.naming.InvalidNameException)3 NamingException (javax.naming.NamingException)3 NoPermissionException (javax.naming.NoPermissionException)3 ServiceUnavailableException (javax.naming.ServiceUnavailableException)3 Response (javax.ws.rs.core.Response)3 LdapConnection (org.apache.archiva.redback.common.ldap.connection.LdapConnection)3 LdapConnectionConfiguration (org.apache.archiva.redback.common.ldap.connection.LdapConnectionConfiguration)3 LdapException (org.apache.archiva.redback.common.ldap.connection.LdapException)3 EditableRepositoryGroup (org.apache.archiva.repository.EditableRepositoryGroup)3 LdapConfiguration (org.apache.archiva.rest.api.v2.model.LdapConfiguration)3 ArrayList (java.util.ArrayList)2