use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class DefaultRepositoryGroupService method updateRepositoryGroup.
@Override
public RepositoryGroup updateRepositoryGroup(final String repositoryGroupId, final RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
if (StringUtils.isEmpty(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND, ""), 404);
}
if (!repositoryRegistry.hasRepositoryGroup(repositoryGroupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_NOT_FOUND), 404);
}
repositoryGroup.setId(repositoryGroupId);
try {
RepositoryGroupConfiguration configuration = toConfig(repositoryGroup);
CheckedResult<org.apache.archiva.repository.RepositoryGroup, Map<String, List<ValidationError>>> validationResult = repositoryRegistry.putRepositoryGroupAndValidate(configuration);
if (validationResult.isValid()) {
httpServletResponse.setStatus(201);
return RepositoryGroup.of(validationResult.getRepository());
} else {
throw ValidationException.of(validationResult.getResult());
}
} catch (RepositoryException e) {
log.error("Exception during repository group update: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_UPDATE_FAILED, e.getMessage()));
}
}
use of org.apache.archiva.repository.validation.ValidationError 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"));
}
use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class RepositoryGroupHandlerTest method validateRepositoryIfExisting.
@Test
void validateRepositoryIfExisting() throws IOException, RepositoryException {
final String id = "test-group-11";
try {
RepositoryGroupHandler groupHandler = createHandler();
EditableRepositoryGroup repositoryGroup = createRepository(id, "n-" + id);
repositoryGroup.setMergedIndexTTL(5);
groupHandler.put(repositoryGroup);
CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.validateRepository(repositoryGroup);
assertNotNull(result);
assertEquals(1, result.getResult().size());
} finally {
removeGroupFromConfig(id);
}
}
use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class ManagedRepositoryHandlerTest method putWithCheck_invalid.
@Test
void putWithCheck_invalid() throws RepositoryException {
final String id = "test-repo-07";
final String name = "n-" + id;
try {
ManagedRepositoryHandler repoHandler = createHandler();
BasicManagedRepositoryValidator checker = new BasicManagedRepositoryValidator(configurationHandler);
checker.setRepositoryRegistry(repositoryRegistry);
ManagedRepositoryConfiguration configuration = new ManagedRepositoryConfiguration();
configuration.setId("");
configuration.setName(name);
CheckedResult<ManagedRepository, Map<String, List<ValidationError>>> result = repoHandler.putWithCheck(configuration, checker);
assertNull(repoHandler.get(id));
assertNotNull(result.getResult());
assertNotNull(result.getResult().get("id"));
assertEquals(2, result.getResult().get("id").size());
assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
assertFalse(hasRepositoryInConfig(id));
assertFalse(hasRepositoryInConfig(""));
} finally {
removeRepositoryFromConfig(id);
}
}
use of org.apache.archiva.repository.validation.ValidationError in project archiva by apache.
the class ManagedRepositoryHandlerTest method validateRepository.
@Test
void validateRepository() throws IOException {
final String id = "test-repo-10";
ManagedRepositoryHandler repoHandler = createHandler();
EditableManagedRepository repository = createRepository(id, "n-" + id);
CheckedResult<ManagedRepository, Map<String, List<ValidationError>>> result = repoHandler.validateRepository(repository);
assertNotNull(result);
assertEquals(0, result.getResult().size());
repository = createRepository(id, "n-test-repo-10###");
result = repoHandler.validateRepository(repository);
assertNotNull(result);
assertEquals(1, result.getResult().size());
assertNotNull(result.getResult().get("name"));
}
Aggregations