use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class DefaultArchivaAdministration method addFileTypePattern.
@Override
public void addFileTypePattern(String fileTypeId, String pattern, AuditInformation auditInformation) throws RepositoryAdminException {
Configuration configuration = getArchivaConfiguration().getConfiguration();
org.apache.archiva.configuration.model.FileType fileType = getFileTypeById(fileTypeId, configuration);
if (fileType == null) {
return;
}
if (fileType.getPatterns().contains(pattern)) {
throw new RepositoryAdminException("File type [" + fileTypeId + "] already contains pattern [" + pattern + "]");
}
fileType.addPattern(pattern);
saveConfiguration(configuration);
triggerAuditEvent("", "", AuditEvent.ADD_PATTERN, auditInformation);
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class DefaultManagedRepositoryAdmin method addManagedRepository.
@Override
public Boolean addManagedRepository(ManagedRepository managedRepository, boolean needStageRepo, AuditInformation auditInformation) throws RepositoryAdminException {
log.debug("addManagedRepository {}, {}, {}", managedRepository.getId(), needStageRepo, auditInformation);
getRepositoryCommonValidator().basicValidation(managedRepository, false);
getRepositoryCommonValidator().validateManagedRepository(managedRepository);
triggerAuditEvent(managedRepository.getId(), null, AuditEvent.ADD_MANAGED_REPO, auditInformation);
ManagedRepositoryConfiguration repoConfig = getRepositoryConfiguration(managedRepository);
if (needStageRepo) {
repoConfig.setStageRepoNeeded(true);
}
Configuration configuration = getArchivaConfiguration().getConfiguration();
try {
org.apache.archiva.repository.ManagedRepository newRepo = repositoryRegistry.putRepository(repoConfig);
log.debug("Added new repository {}", newRepo.getId());
addRepositoryRoles(newRepo.getId());
// scan repository when adding of repository is successful
try {
if (newRepo.isScanned()) {
scanRepository(newRepo.getId(), true);
}
org.apache.archiva.repository.ManagedRepository stagingRepo = newRepo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
if (stagingRepo != null) {
if (stagingRepo.isScanned()) {
scanRepository(stagingRepo.getId(), true);
}
addRepositoryRoles(stagingRepo.getId());
}
} catch (Exception e) {
log.warn("Unable to scan repository [{}]: {}", newRepo.getId(), e.getMessage(), e);
}
} catch (RepositoryException e) {
log.error("Could not add managed repository {}" + managedRepository);
throw new RepositoryAdminException("Could not add repository " + e.getMessage());
} catch (RoleManagerException e) {
log.error("Could not add repository roles for repository [{}]: {}", managedRepository.getId(), e.getMessage(), e);
throw new RepositoryAdminException("Could not add roles to repository " + e.getMessage());
}
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class DefaultManagedRepositoryAdmin method deleteManagedRepository.
@Override
public Boolean deleteManagedRepository(String repositoryId, AuditInformation auditInformation, boolean deleteContent) throws RepositoryAdminException {
Configuration config = getArchivaConfiguration().getConfiguration();
ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById(repositoryId);
if (repoConfig != null) {
log.debug("Repo location " + repoConfig.getLocation());
org.apache.archiva.repository.ManagedRepository repo = repositoryRegistry.getManagedRepository(repositoryId);
org.apache.archiva.repository.ManagedRepository stagingRepository = null;
if (repo != null) {
if (repo.supportsFeature(StagingRepositoryFeature.class)) {
stagingRepository = repo.getFeature(StagingRepositoryFeature.class).getStagingRepository();
}
} else {
throw new RepositoryAdminException("A repository with that id does not exist");
}
triggerAuditEvent(repositoryId, null, AuditEvent.DELETE_MANAGED_REPO, auditInformation);
if (repoConfig != null) {
deleteManagedRepository(repoConfig, deleteContent, config, false);
}
// stage repo exists ?
if (stagingRepository != null) {
// do not trigger event when deleting the staged one
ManagedRepositoryConfiguration stagingRepositoryConfig = config.findManagedRepositoryById(stagingRepository.getId());
if (stagingRepositoryConfig != null) {
deleteManagedRepository(stagingRepositoryConfig, deleteContent, config, true);
}
}
try {
saveConfiguration(config);
} catch (Exception e) {
throw new RepositoryAdminException("Error saving configuration for delete action" + e.getMessage(), e);
}
return Boolean.TRUE;
} else {
return Boolean.FALSE;
}
}
use of org.apache.archiva.configuration.model.Configuration in project archiva by apache.
the class DefaultRepositoryGroupAdmin method updateRepositoryGroup.
private Boolean updateRepositoryGroup(RepositoryGroup repositoryGroup, AuditInformation auditInformation, boolean triggerAuditEvent) throws RepositoryAdminException {
validateRepositoryGroup(repositoryGroup, true);
validateManagedRepositoriesExists(repositoryGroup.getRepositories());
Configuration configuration = getArchivaConfiguration().getConfiguration();
RepositoryGroupConfiguration repositoryGroupConfiguration = configuration.getRepositoryGroupsAsMap().get(repositoryGroup.getId());
repositoryGroupConfiguration.setRepositories(repositoryGroup.getRepositories());
repositoryGroupConfiguration.setMergedIndexPath(repositoryGroup.getMergedIndexPath());
repositoryGroupConfiguration.setMergedIndexTtl(repositoryGroup.getMergedIndexTtl());
repositoryGroupConfiguration.setCronExpression(repositoryGroup.getCronExpression());
try {
repositoryRegistry.putRepositoryGroup(repositoryGroupConfiguration);
} catch (RepositoryException e) {
log.error("Could not update the repository group in the registry: {}", e.getMessage(), e);
throw RepositoryAdminException.ofKey("repository_group.registry.update_error", e, repositoryGroup.getId(), e.getMessage());
}
org.apache.archiva.repository.RepositoryGroup rg = repositoryRegistry.getRepositoryGroup(repositoryGroup.getId());
triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.MODIFY_REPO_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.configuration.model.Configuration 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;
}
Aggregations