use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupAdmin method addRepositoryToGroup.
@Override
public Boolean addRepositoryToGroup(String repositoryGroupId, String repositoryId, AuditInformation auditInformation) throws RepositoryAdminException {
org.apache.archiva.repository.RepositoryGroup repositoryGroup = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
if (repositoryGroup == null) {
throw EntityNotFoundException.ofMessage("Repository group with id " + repositoryGroupId + " doesn't not exists so cannot add repository to it", repositoryGroupId);
}
if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
throw RepositoryAdminException.ofKey("repository_group.not_editable", repositoryGroupId);
}
EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
if (editableRepositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
throw new EntityExistsException("Repository group with id " + repositoryGroupId + " already contain repository with id" + repositoryId);
}
org.apache.archiva.repository.ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repositoryId);
if (managedRepo == null) {
throw EntityNotFoundException.ofMessage("Repository with id " + repositoryId + " does not exist", repositoryId);
}
editableRepositoryGroup.addRepository(managedRepo);
try {
repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
} catch (RepositoryException e) {
throw new RepositoryAdminException("Could not store the repository group " + repositoryGroupId, e);
}
triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.ADD_REPO_TO_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class RepositoryGroupHandler method put.
/**
* Adds a new repository group or updates the repository with the same id, if it exists already.
* The configuration is saved immediately.
*
* @param repositoryGroupConfiguration the repository configuration
* @return the updated or created repository
* @throws RepositoryException if an error occurs, or the configuration is not valid.
*/
@Override
public RepositoryGroup put(RepositoryGroupConfiguration repositoryGroupConfiguration) throws RepositoryException {
final String id = repositoryGroupConfiguration.getId();
final RepositoryType repositoryType = RepositoryType.valueOf(repositoryGroupConfiguration.getType());
final RepositoryProvider provider = getProvider(repositoryType);
RepositoryGroup currentRepository;
ReentrantReadWriteLock.WriteLock configLock = this.getConfigurationHandler().getLock().writeLock();
configLock.lock();
try {
Configuration configuration = this.getConfigurationHandler().getBaseConfiguration();
currentRepository = getRepositories().get(id);
RepositoryGroup oldRepository = currentRepository == null ? null : clone(currentRepository, id);
try {
boolean updated = false;
if (currentRepository == null) {
currentRepository = put(repositoryGroupConfiguration, configuration);
} else {
setRepositoryGroupDefaults(repositoryGroupConfiguration);
provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, repositoryGroupConfiguration);
updated = true;
pushEvent(LifecycleEvent.UPDATED, currentRepository);
}
registerNewRepository(repositoryGroupConfiguration, currentRepository, configuration, updated);
} catch (IndeterminateConfigurationException | RegistryException | RepositoryException e) {
// Trying a rollback
if (oldRepository != null) {
RepositoryGroupConfiguration oldCfg = provider.getRepositoryGroupConfiguration(oldRepository);
provider.updateRepositoryGroupInstance((EditableRepositoryGroup) currentRepository, oldCfg);
rollback(configuration, oldRepository, e, oldCfg);
} else {
getRepositories().remove(id);
}
log.error("Could not save the configuration for repository group {}: {}", id, e.getMessage(), e);
if (e instanceof RepositoryException) {
throw (RepositoryException) e;
} else {
throw new RepositoryException("Could not save the configuration for repository group " + id + ": " + e.getMessage());
}
}
} finally {
configLock.unlock();
}
return currentRepository;
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class BasicRepositoryGroupValidatorTest method applyWithExisting.
@Test
void applyWithExisting() throws IOException, RepositoryException {
BasicRepositoryGroupValidator validator = new BasicRepositoryGroupValidator(configurationHandler);
validator.setRepositoryRegistry(repositoryRegistry);
EditableRepositoryGroup group = createGroup("test", "test");
group.setMergedIndexTTL(360);
repositoryRegistry.putRepositoryGroup(group);
EditableRepositoryGroup group2 = createGroup("test", "test2");
group2.setMergedIndexTTL(360);
ValidationResponse<RepositoryGroup> result = validator.apply(group2);
assertNotNull(result);
assertFalse(result.isValid());
assertEquals("group_exists", result.getResult().get("id").get(0).getType());
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class RepositoryGroupHandler method put.
@Override
public RepositoryGroup put(RepositoryGroupConfiguration repositoryGroupConfiguration, Configuration configuration) throws RepositoryException {
final String id = repositoryGroupConfiguration.getId();
final RepositoryType repoType = RepositoryType.valueOf(repositoryGroupConfiguration.getType());
RepositoryGroup repo;
setRepositoryGroupDefaults(repositoryGroupConfiguration);
if (getRepositories().containsKey(id)) {
repo = clone(getRepositories().get(id), id);
if (repo instanceof EditableRepositoryGroup) {
getProvider(repoType).updateRepositoryGroupInstance((EditableRepositoryGroup) repo, repositoryGroupConfiguration);
} else {
throw new RepositoryException("The repository is not editable " + id);
}
} else {
repo = getProvider(repoType).createRepositoryGroup(repositoryGroupConfiguration);
setLastState(repo, RepositoryState.CREATED);
}
replaceOrAddRepositoryConfig(repositoryGroupConfiguration, configuration);
updateReferences(repo, repositoryGroupConfiguration);
setLastState(repo, RepositoryState.REFERENCES_SET);
return repo;
}
Aggregations