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;
}
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();
}
}
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();
}
}
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);
}
}
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);
}
}
Aggregations