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