use of org.apache.archiva.rest.api.v2.model.RepositoryGroup 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.rest.api.v2.model.RepositoryGroup in project archiva by apache.
the class DefaultRepositoryGroupService method toConfig.
private RepositoryGroupConfiguration toConfig(RepositoryGroup group) {
RepositoryGroupConfiguration result = new RepositoryGroupConfiguration();
result.setId(group.getId());
result.setName(group.getName());
result.setLocation(group.getLocation());
result.setRepositories(group.getRepositories());
MergeConfiguration mergeConfig = group.getMergeConfiguration();
if (mergeConfig != null) {
result.setMergedIndexPath(mergeConfig.getMergedIndexPath());
result.setMergedIndexTtl(mergeConfig.getMergedIndexTtlMinutes());
result.setCronExpression(mergeConfig.getIndexMergeSchedule());
}
return result;
}
use of org.apache.archiva.rest.api.v2.model.RepositoryGroup 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.rest.api.v2.model.RepositoryGroup in project archiva by apache.
the class NativeRepositoryGroupServiceTest method testAddGroup.
@Test
void testAddGroup() {
String token = getAdminToken();
try {
Map<String, Object> jsonAsMap = new HashMap<>();
jsonAsMap.put("id", "group_001");
jsonAsMap.put("name", "group_001");
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").then().statusCode(201).extract().response();
assertNotNull(response);
RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
assertNotNull(result);
response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(1, resultList.getPagination().getTotalCount());
} finally {
given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_001").then().statusCode(200);
}
}
use of org.apache.archiva.rest.api.v2.model.RepositoryGroup in project archiva by apache.
the class NativeRepositoryGroupServiceTest method testAddRepositoryToGroup.
@Test
void testAddRepositoryToGroup() {
String token = getAdminToken();
try {
Map<String, Object> jsonAsMap = new HashMap<>();
jsonAsMap.put("id", "group_001");
jsonAsMap.put("name", "group_001");
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).post("").prettyPeek().then().statusCode(201).extract().response();
assertNotNull(response);
RepositoryGroup result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
assertNotNull(result);
response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult resultList = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(1, resultList.getPagination().getTotalCount());
response = given().spec(getRequestSpec(token)).contentType(JSON).when().body(jsonAsMap).put("group_001/repositories/internal").prettyPeek().then().statusCode(200).extract().response();
assertNotNull(response);
result = response.getBody().jsonPath().getObject("", RepositoryGroup.class);
assertNotNull(result);
assertEquals(1, result.getRepositories().size());
assertTrue(result.getRepositories().contains("internal"));
} finally {
given().spec(getRequestSpec(token)).contentType(JSON).when().delete("group_001");
}
}
Aggregations