use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class BasicRepositoryGroupValidatorTest method applyWithEmptyId.
@Test
void applyWithEmptyId() throws IOException {
BasicRepositoryGroupValidator validator = new BasicRepositoryGroupValidator(configurationHandler);
EditableRepositoryGroup group = createGroup("", "test");
group.setMergedIndexTTL(0);
ValidationResponse<RepositoryGroup> result = validator.apply(group);
assertNotNull(result);
assertFalse(result.isValid());
assertTrue(result.getResult().containsKey("id"));
assertEquals("repository_group", result.getResult().get("id").get(0).getCategory());
assertEquals("empty", result.getResult().get("id").get(0).getType());
assertEquals("id", result.getResult().get("id").get(0).getAttribute());
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class BasicRepositoryGroupValidatorTest method applyWithBadTTL.
@Test
void applyWithBadTTL() throws IOException {
BasicRepositoryGroupValidator validator = new BasicRepositoryGroupValidator(configurationHandler);
EditableRepositoryGroup group = createGroup("test", "test");
group.setMergedIndexTTL(0);
ValidationResponse<RepositoryGroup> result = validator.apply(group);
assertNotNull(result);
assertFalse(result.isValid());
assertTrue(result.getResult().containsKey("merged_index_ttl"));
assertEquals("repository_group", result.getResult().get("merged_index_ttl").get(0).getCategory());
assertEquals("min", result.getResult().get("merged_index_ttl").get(0).getType());
assertEquals("merged_index_ttl", result.getResult().get("merged_index_ttl").get(0).getAttribute());
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class MavenRepositoryProviderTest method createRepositoryGroup.
@Test
public void createRepositoryGroup() {
EditableRepositoryGroup gr = provider.createRepositoryGroup("group1", "Group 1");
assertEquals("group1", gr.getId());
assertEquals("Group 1", gr.getName());
assertEquals(MavenRepositoryGroup.class, gr.getClass());
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class RepositoryGroupHandlerTest method validateRepositoryForUpdate.
@Test
void validateRepositoryForUpdate() throws IOException, RepositoryException {
final String id = "test-group-12";
try {
RepositoryGroupHandler groupHandler = createHandler();
EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
repositoryGroup.setMergedIndexTTL(5);
groupHandler.put(repositoryGroup);
CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepositoryForUpdate(repositoryGroup);
assertNotNull(result);
assertEquals(0, result.getResult().size());
} finally {
removeGroupFromConfig(id);
}
}
use of org.apache.archiva.repository.EditableRepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupService method deleteRepositoryFromGroup.
@Override
public RepositoryGroup deleteRepositoryFromGroup(final String repositoryGroupId, final String repositoryId) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, repositoryGroupId), 404);
}
if (StringUtils.isEmpty(repositoryId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId), 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.getRepositories().stream().noneMatch(r -> repositoryId.equals(r.getId()))) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_NOT_FOUND, repositoryId), 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;
editableRepositoryGroup.removeRepository(repositoryId);
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);
}
}
Aggregations