use of org.apache.archiva.rest.api.v2.model.Repository 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.Repository in project archiva by apache.
the class NativeRepositoryServiceTest method testGetRepositories.
@Test
void testGetRepositories() {
String token = getAdminToken();
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult<Repository> repositoryPagedResult = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(3, repositoryPagedResult.getPagination().getTotalCount());
List<Repository> data = response.getBody().jsonPath().getList("data", Repository.class);
assertTrue(data.stream().anyMatch(p -> "central".equals(p.getId())));
assertTrue(data.stream().anyMatch(p -> "internal".equals(p.getId())));
assertTrue(data.stream().anyMatch(p -> "snapshots".equals(p.getId())));
Repository snapshotRepo = data.stream().filter(p -> "snapshots".equals(p.getId())).findFirst().get();
assertEquals("Archiva Managed Snapshot Repository", snapshotRepo.getName());
assertEquals("MAVEN", snapshotRepo.getType());
assertEquals("managed", snapshotRepo.getCharacteristic());
assertEquals("default", snapshotRepo.getLayout());
assertTrue(snapshotRepo.isScanned());
assertTrue(snapshotRepo.isIndex());
Repository centralRepo = data.stream().filter(p -> "central".equals(p.getId())).findFirst().get();
assertEquals("Central Repository", centralRepo.getName());
assertEquals("MAVEN", centralRepo.getType());
assertEquals("remote", centralRepo.getCharacteristic());
assertEquals("default", centralRepo.getLayout());
}
use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.
the class DefaultMavenManagedRepositoryService method addManagedRepository.
@Override
public MavenManagedRepository addManagedRepository(MavenManagedRepository managedRepository) throws ArchivaRestServiceException {
final String repoId = managedRepository.getId();
if (StringUtils.isEmpty(repoId)) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_INVALID_ID, repoId), 422);
}
Repository repo = repositoryRegistry.getRepository(repoId);
if (repo != null) {
httpServletResponse.setHeader("Location", uriInfo.getAbsolutePathBuilder().path(repoId).build().toString());
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ID_EXISTS, repoId), 303);
}
try {
repositoryRegistry.putRepository(mapper.map(managedRepository));
httpServletResponse.setStatus(201);
return mapper.reverseMap(repositoryRegistry.getManagedRepository(repoId));
} catch (RepositoryException e) {
log.error("Could not create repository: {}", e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_ADD_FAILED, repoId));
}
}
use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.
the class NativeRepositoryServiceTest method testGetFilteredRepositories.
@Test
void testGetFilteredRepositories() {
String token = getAdminToken();
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().queryParam("q", "central").get("").then().statusCode(200).extract().response();
assertNotNull(response);
PagedResult<Repository> repositoryPagedResult = response.getBody().jsonPath().getObject("", PagedResult.class);
assertEquals(1, repositoryPagedResult.getPagination().getTotalCount());
List<Repository> data = response.getBody().jsonPath().getList("data", Repository.class);
assertTrue(data.stream().anyMatch(p -> "central".equals(p.getId())));
}
Aggregations