use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration 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.ManagedRepositoryConfiguration in project archiva by apache.
the class ManagedRepositoryHandler method clone.
@Override
public ManagedRepository clone(ManagedRepository repo, String id) throws RepositoryException {
RepositoryProvider provider = getProvider(repo.getType());
ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(repo);
cfg.setId(id);
ManagedRepository cloned = provider.createManagedInstance(cfg);
cloned.registerEventHandler(RepositoryEvent.ANY, repositoryHandlerManager);
setLastState(cloned, RepositoryState.CREATED);
return cloned;
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class ManagedRepositoryHandler method newOrUpdateInstancesFromConfig.
public Map<String, ManagedRepository> newOrUpdateInstancesFromConfig(Map<String, ManagedRepository> currentInstances) {
try {
List<ManagedRepositoryConfiguration> managedRepoConfigs = new ArrayList<>(getConfigurationHandler().getBaseConfiguration().getManagedRepositories());
if (managedRepoConfigs == null) {
return Collections.emptyMap();
}
Map<String, ManagedRepository> result = new HashMap<>();
for (ManagedRepositoryConfiguration repoConfig : managedRepoConfigs) {
String id = repoConfig.getId();
if (result.containsKey(id)) {
log.error("There are repositories with the same id in the configuration: {}", id);
continue;
}
ManagedRepository repo;
if (currentInstances.containsKey(id)) {
repo = currentInstances.remove(id);
getProvider(repo.getType()).updateManagedInstance((EditableManagedRepository) repo, repoConfig);
updateReferences(repo, repoConfig);
} else {
repo = newInstance(repoConfig);
}
result.put(id, repo);
if (repo.supportsFeature(StagingRepositoryFeature.class)) {
StagingRepositoryFeature stagF = repo.getFeature(StagingRepositoryFeature.class);
if (stagF.getStagingRepository() != null) {
String stagingId = getStagingId(id);
ManagedRepository stagingRepo;
if (currentInstances.containsKey(stagingId)) {
stagingRepo = currentInstances.remove(stagingId);
managedRepoConfigs.stream().filter(cfg -> stagingId.equals(cfg.getId())).findFirst().ifPresent(stagingRepoConfig -> {
try {
getProvider(stagingRepo.getType()).updateManagedInstance((EditableManagedRepository) stagingRepo, stagingRepoConfig);
updateReferences(stagingRepo, stagingRepoConfig);
} catch (RepositoryException e) {
log.error("Could not update staging repo {}: {}", stagingId, e.getMessage());
}
});
} else {
stagingRepo = getStagingRepository(repo);
}
if (stagingRepo != null) {
result.put(stagingRepo.getId(), stagingRepo);
}
}
}
}
return result;
} catch (Throwable e) {
log.error("Could not initialize repositories from config: {}", e.getMessage(), e);
return new HashMap<>();
}
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class ManagedRepositoryHandler method getStagingRepository.
private ManagedRepository getStagingRepository(ManagedRepository baseRepo) throws RepositoryException {
ManagedRepository stageRepo = get(getStagingId(baseRepo.getId()));
final RepositoryType type = baseRepo.getType();
if (stageRepo == null) {
RepositoryProvider provider = getProvider(type);
ManagedRepositoryConfiguration cfg = provider.getManagedConfiguration(baseRepo);
stageRepo = provider.createStagingInstance(cfg);
if (stageRepo.supportsFeature(StagingRepositoryFeature.class)) {
stageRepo.getFeature(StagingRepositoryFeature.class).setStageRepoNeeded(false);
}
updateReferences(stageRepo, cfg);
}
return stageRepo;
}
use of org.apache.archiva.configuration.model.ManagedRepositoryConfiguration in project archiva by apache.
the class ArchivaRepositoryRegistryTest method putManagedRepositoryFromConfig.
@Test
public void putManagedRepositoryFromConfig() throws Exception {
ManagedRepositoryConfiguration cfg = new ManagedRepositoryConfiguration();
cfg.setId("test002");
cfg.setName("This is test 002");
ManagedRepository repo = repositoryRegistry.putRepository(cfg);
assertNotNull(repo);
assertEquals("test002", repo.getId());
assertEquals("This is test 002", repo.getName());
assertNotNull(repo.getContent());
archivaConfiguration.reload();
Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
assertEquals(5, repos.size());
ManagedRepository internalRepo = repositoryRegistry.getManagedRepository("internal");
cfg = new ManagedRepositoryConfiguration();
cfg.setId("internal");
cfg.setName("This is internal test 002");
repo = repositoryRegistry.putRepository(cfg);
assertSame(internalRepo, repo);
assertEquals("This is internal test 002", repo.getName());
assertEquals(5, repositoryRegistry.getManagedRepositories().size());
repositoryRegistry.reload();
assertEquals(5, repositoryRegistry.getManagedRepositories().size());
}
Aggregations