use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class RepositoryGroupHandler method updateReferences.
@Override
public void updateReferences(RepositoryGroup repo, RepositoryGroupConfiguration repositoryConfiguration) {
if (repo instanceof EditableRepositoryGroup && repositoryConfiguration != null) {
EditableRepositoryGroup eGroup = (EditableRepositoryGroup) repo;
RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration> managedHandler = repositoryRegistry.getHandler(ManagedRepository.class, ManagedRepositoryConfiguration.class);
eGroup.setRepositories(repositoryConfiguration.getRepositories().stream().map(managedHandler::get).collect(Collectors.toList()));
}
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupAdmin method deleteRepositoryFromGroup.
@Override
public Boolean deleteRepositoryFromGroup(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 remove repository from it", repositoryGroupId);
}
if (!repositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
throw EntityNotFoundException.ofMessage("repositoryGroup with id " + repositoryGroupId + " doesn't not contains repository with id" + repositoryId, repositoryId);
}
if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
throw RepositoryAdminException.ofKey("repository_group.not_editable", repositoryGroupId);
}
EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
editableRepositoryGroup.removeRepository(repositoryId);
try {
repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
} catch (RepositoryException e) {
throw new RepositoryAdminException("Could not store repository group " + repositoryGroupId, e);
}
triggerAuditEvent(repositoryGroup.getId(), null, AuditEvent.DELETE_REPO_FROM_GROUP, auditInformation);
return Boolean.TRUE;
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupService method addRepositoryToGroup.
@Override
public RepositoryGroup addRepositoryToGroup(String repositoryGroupId, String repositoryId) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (StringUtils.isEmpty(repositoryId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
}
try {
org.apache.archiva.repository.RepositoryGroup repositoryGroup = repositoryRegistry.getRepositoryGroup(repositoryGroupId);
if (repositoryGroup == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (!(repositoryGroup instanceof EditableRepositoryGroup)) {
log.error("This group instance is not editable: {}", repositoryGroupId);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, ""), 500);
}
EditableRepositoryGroup editableRepositoryGroup = (EditableRepositoryGroup) repositoryGroup;
if (editableRepositoryGroup.getRepositories().stream().anyMatch(repo -> repositoryId.equals(repo.getId()))) {
log.info("Repository {} is already member of group {}", repositoryId, repositoryGroupId);
return RepositoryGroup.of(editableRepositoryGroup);
}
org.apache.archiva.repository.ManagedRepository managedRepo = repositoryRegistry.getManagedRepository(repositoryId);
if (managedRepo == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, ""), 404);
}
editableRepositoryGroup.addRepository(managedRepo);
org.apache.archiva.repository.RepositoryGroup newGroup = repositoryRegistry.putRepositoryGroup(editableRepositoryGroup);
return RepositoryGroup.of(newGroup);
} catch (RepositoryException e) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()), 500);
}
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class RepositoryGroupHandlerTest method put.
@Test
void put() throws IOException, RepositoryException {
final String id = "test-group-04";
try {
RepositoryGroupHandler groupHandler = createHandler();
EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
groupHandler.put(repositoryGroup);
RepositoryGroup storedGroup = groupHandler.get(id);
assertNotNull(storedGroup);
assertEquals(id, storedGroup.getId());
assertEquals("n-" + id, storedGroup.getName());
EditableRepositoryGroup repositoryGroup2 = createRepository(id, "n2-" + id);
groupHandler.put(repositoryGroup2);
storedGroup = groupHandler.get(id);
assertNotNull(storedGroup);
assertEquals(id, storedGroup.getId());
assertEquals("n2-" + id, storedGroup.getName());
assertTrue(hasGroupInConfig(id));
} finally {
removeGroupFromConfig(id);
}
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class RepositoryGroupHandlerTest method validateRepository.
@Test
void validateRepository() throws IOException {
RepositoryGroupHandler groupHandler = createHandler();
final String id = "test-group-10";
EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
repositoryGroup.setMergedIndexTTL(5);
CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepository(repositoryGroup);
assertNotNull(result);
assertEquals(0, result.getResult().size());
repositoryGroup = createRepository(id, "n-test-group-10###");
result = groupHandler.validateRepository(repositoryGroup);
assertNotNull(result);
assertEquals(2, result.getResult().size());
assertNotNull(result.getResult().get("merged_index_ttl"));
assertNotNull(result.getResult().get("name"));
}
Aggregations