use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandlerTest method removeGroupFromConfig.
// Helper method that removes a group from the configuration
private void removeGroupFromConfig(String groupId) {
Configuration configuration = configurationHandler.getBaseConfiguration();
Iterator<RepositoryGroupConfiguration> groupIter = configuration.getRepositoryGroups().iterator();
while (groupIter.hasNext()) {
RepositoryGroupConfiguration group = groupIter.next();
if (groupId.equals(group.getId())) {
groupIter.remove();
break;
}
}
try {
configurationHandler.save(configuration);
} catch (Throwable e) {
System.err.println("Could not remove repo group from config " + groupId);
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandlerTest method testPutWithoutRegister.
@Test
void testPutWithoutRegister() throws RepositoryException {
RepositoryGroupHandler groupHandler = createHandler();
Configuration aCfg = new Configuration();
RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
final String id = "test-group-06";
configuration.setId(id);
configuration.setName("n-" + id);
ArrayList<String> repos = new ArrayList<>();
repos.add("internal");
configuration.setRepositories(repos);
groupHandler.put(configuration, aCfg);
RepositoryGroup repo = groupHandler.get(id);
assertNull(repo);
assertFalse(hasGroupInConfig(id));
assertTrue(aCfg.getRepositoryGroups().stream().anyMatch(g -> g != null && id.equals(g.getId())));
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandlerTest method remove.
@Test
void remove() throws RepositoryException {
RepositoryGroupHandler groupHandler = createHandler();
RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
final String id = "test-group-08";
configuration.setId(id);
configuration.setName("n-" + id);
groupHandler.put(configuration);
assertTrue(hasGroupInConfig(id));
assertNotNull(groupHandler.get(id));
groupHandler.remove(id);
assertNull(groupHandler.get(id));
assertFalse(hasGroupInConfig(id));
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class RepositoryGroupHandlerTest method putWithCheck_invalid.
@Test
void putWithCheck_invalid() throws RepositoryException {
final String id = "test-group-07";
final String name = "n-" + id;
try {
RepositoryGroupHandler groupHandler = createHandler();
BasicRepositoryGroupValidator checker = new BasicRepositoryGroupValidator(configurationHandler);
RepositoryGroupConfiguration configuration = new RepositoryGroupConfiguration();
configuration.setId("");
configuration.setName(name);
ArrayList<String> repos = new ArrayList<>();
repos.add("internal");
configuration.setRepositories(repos);
CheckedResult<RepositoryGroup, Map<String, List<ValidationError>>> result = groupHandler.putWithCheck(configuration, checker);
assertNull(groupHandler.get(id));
assertNotNull(result.getResult());
assertNotNull(result.getResult().get("id"));
assertEquals(1, result.getResult().get("id").size());
assertEquals(ISEMPTY, result.getResult().get("id").get(0).getType());
assertFalse(hasGroupInConfig(id));
assertFalse(hasGroupInConfig(""));
} finally {
removeGroupFromConfig(id);
}
}
use of org.apache.archiva.configuration.model.RepositoryGroupConfiguration in project archiva by apache.
the class DefaultRepositoryGroupService method addRepositoryGroup.
@Override
public RepositoryGroup addRepositoryGroup(RepositoryGroup repositoryGroup) throws ArchivaRestServiceException {
final String groupId = repositoryGroup.getId();
if (StringUtils.isEmpty(groupId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, groupId), 422);
}
if (repositoryRegistry.hasRepositoryGroup(groupId)) {
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(groupId).build().toString());
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, groupId), 303);
}
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) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_GROUP_ADD_FAILED));
}
}
Aggregations