Search in sources :

Example 21 with RepositoryAdminException

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

the class DefaultFileUploadService method save.

@Override
public Boolean save(String repositoryId, String groupId, String artifactId, String version, String packaging, boolean generatePom) throws ArchivaRestServiceException {
    repositoryId = StringUtils.trim(repositoryId);
    groupId = StringUtils.trim(groupId);
    artifactId = StringUtils.trim(artifactId);
    version = StringUtils.trim(version);
    packaging = StringUtils.trim(packaging);
    List<FileMetadata> fileMetadatas = getSessionFilesList();
    if (fileMetadatas == null || fileMetadatas.isEmpty()) {
        return Boolean.FALSE;
    }
    try {
        ManagedRepository managedRepository = managedRepositoryAdmin.getManagedRepository(repositoryId);
        if (managedRepository == null) {
            // TODO i18n ?
            throw new ArchivaRestServiceException("Cannot find managed repository with id " + repositoryId, Response.Status.BAD_REQUEST.getStatusCode(), null);
        }
        if (VersionUtil.isSnapshot(version) && !managedRepository.isSnapshots()) {
            // TODO i18n ?
            throw new ArchivaRestServiceException("Managed repository with id " + repositoryId + " do not accept snapshots", Response.Status.BAD_REQUEST.getStatusCode(), null);
        }
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), e);
    }
    // get from the session file with groupId/artifactId
    Iterable<FileMetadata> filesToAdd = Iterables.filter(fileMetadatas, new Predicate<FileMetadata>() {

        public boolean apply(FileMetadata fileMetadata) {
            return fileMetadata != null && !fileMetadata.isPomFile();
        }
    });
    Iterator<FileMetadata> iterator = filesToAdd.iterator();
    boolean pomGenerated = false;
    while (iterator.hasNext()) {
        FileMetadata fileMetadata = iterator.next();
        log.debug("fileToAdd: {}", fileMetadata);
        saveFile(repositoryId, fileMetadata, generatePom && !pomGenerated, groupId, artifactId, version, packaging);
        pomGenerated = true;
        deleteFile(fileMetadata.getServerFileName());
    }
    filesToAdd = Iterables.filter(fileMetadatas, new Predicate<FileMetadata>() {

        @Override
        public boolean apply(FileMetadata fileMetadata) {
            return fileMetadata != null && fileMetadata.isPomFile();
        }
    });
    iterator = filesToAdd.iterator();
    while (iterator.hasNext()) {
        FileMetadata fileMetadata = iterator.next();
        log.debug("fileToAdd: {}", fileMetadata);
        savePomFile(repositoryId, fileMetadata, groupId, artifactId, version, packaging);
        deleteFile(fileMetadata.getServerFileName());
    }
    return Boolean.TRUE;
}
Also used : ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) FileMetadata(org.apache.archiva.web.model.FileMetadata) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) Predicate(com.google.common.base.Predicate)

Example 22 with RepositoryAdminException

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

the class DefaultMergeRepositoriesService method doMerge.

protected void doMerge(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 23 with RepositoryAdminException

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

the class DefaultMergeRepositoriesService method mergeBySkippingConflicts.

public void mergeBySkippingConflicts(String sourceRepositoryId, String targetRepositoryId) throws RepositoryMergerException, ArchivaRestServiceException {
    RepositorySession repositorySession = repositorySessionFactory.createSession();
    try {
        List<ArtifactMetadata> conflictSourceArtifacts = repositoryMerger.getConflictingArtifacts(repositorySession.getRepository(), sourceRepositoryId, targetRepositoryId);
        MetadataRepository metadataRepository = repositorySession.getRepository();
        List<ArtifactMetadata> sourceArtifacts = metadataRepository.getArtifacts(sourceRepositoryId);
        sourceArtifacts.removeAll(conflictSourceArtifacts);
        ManagedRepository repository = managedRepositoryAdmin.getManagedRepository(targetRepositoryId);
        if (repository.isReleases() && !repository.isSnapshots()) {
            mergeWithOutSnapshots(metadataRepository, sourceArtifacts, sourceRepositoryId, targetRepositoryId);
        } else {
            Filter<ArtifactMetadata> artifactsWithOutConflicts = new IncludesFilter<ArtifactMetadata>(sourceArtifacts);
            repositoryMerger.merge(metadataRepository, sourceRepositoryId, targetRepositoryId, artifactsWithOutConflicts);
            for (ArtifactMetadata metadata : sourceArtifacts) {
                triggerAuditEvent(targetRepositoryId, metadata.getId(), AuditEvent.MERGING_REPOSITORIES);
            }
        }
        doScanRepository(targetRepositoryId, false);
    } catch (MetadataRepositoryException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    } finally {
        repositorySession.close();
    }
}
Also used : MetadataRepositoryException(org.apache.archiva.metadata.repository.MetadataRepositoryException) MetadataRepository(org.apache.archiva.metadata.repository.MetadataRepository) ManagedRepository(org.apache.archiva.admin.model.beans.ManagedRepository) IncludesFilter(org.apache.archiva.metadata.repository.filter.IncludesFilter) ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) RepositorySession(org.apache.archiva.metadata.repository.RepositorySession) ArtifactMetadata(org.apache.archiva.metadata.model.ArtifactMetadata)

Example 24 with RepositoryAdminException

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

the class DefaultArchivaAdministrationService method setUiConfiguration.

@Override
public void setUiConfiguration(UiConfiguration uiConfiguration) throws ArchivaRestServiceException {
    try {
        // fix for MRM-1757
        // strip any trailing '/' at the end of the url so it won't affect url/link calculations in UI
        uiConfiguration.setApplicationUrl(StringUtils.stripEnd(uiConfiguration.getApplicationUrl(), "/"));
        archivaAdministration.updateUiConfiguration(uiConfiguration);
    } catch (RepositoryAdminException e) {
        throw new ArchivaRestServiceException(e.getMessage(), e);
    }
}
Also used : ArchivaRestServiceException(org.apache.archiva.rest.api.services.ArchivaRestServiceException) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException)

Example 25 with RepositoryAdminException

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

the class ArchivaLdapRoleMapperConfiguration method setLdapGroupMappings.

@Override
public void setLdapGroupMappings(Map<String, List<String>> mappings) throws MappingException {
    try {
        RedbackRuntimeConfiguration redbackRuntimeConfiguration = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration();
        List<LdapGroupMapping> ldapGroupMappings = new ArrayList<>(mappings.size());
        for (Map.Entry<String, List<String>> entry : mappings.entrySet()) {
            ldapGroupMappings.add(new LdapGroupMapping(entry.getKey(), entry.getValue()));
        }
        redbackRuntimeConfiguration.setLdapGroupMappings(ldapGroupMappings);
        redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration(redbackRuntimeConfiguration);
    } catch (RepositoryAdminException e) {
        throw new MappingException(e.getMessage(), e);
    }
}
Also used : LdapGroupMapping(org.apache.archiva.admin.model.beans.LdapGroupMapping) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) RedbackRuntimeConfiguration(org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) HashMap(java.util.HashMap) Map(java.util.Map) MappingException(org.apache.archiva.redback.common.ldap.MappingException)

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