use of org.apache.archiva.rest.api.v2.model.MavenManagedRepository in project archiva by apache.
the class NativeMavenManagedRepositoryServiceTest method testGetRepositories.
@Test
@Order(1)
void testGetRepositories() {
String token = getAdminToken();
Response response = given().spec(getRequestSpec(token)).contentType(JSON).when().get("").then().statusCode(200).extract().response();
JsonPath json = response.getBody().jsonPath();
assertEquals(2, json.getInt("pagination.total_count"));
assertEquals(0, json.getInt("pagination.offset"));
assertEquals(Integer.valueOf(RestConfiguration.DEFAULT_PAGE_LIMIT), json.getInt("pagination.limit"));
List<MavenManagedRepository> repositories = json.getList("data", MavenManagedRepository.class);
assertEquals("internal", repositories.get(0).getId());
assertEquals("snapshots", repositories.get(1).getId());
}
use of org.apache.archiva.rest.api.v2.model.MavenManagedRepository in project archiva by apache.
the class DefaultMavenManagedRepositoryService method getManagedRepositories.
@Override
public PagedResult<MavenManagedRepository> getManagedRepositories(final String searchTerm, final Integer offset, final Integer limit, final List<String> orderBy, final String order) throws ArchivaRestServiceException {
try {
Collection<ManagedRepository> repos = repositoryRegistry.getManagedRepositories();
final Predicate<ManagedRepository> queryFilter = QUERY_HELPER.getQueryFilter(searchTerm).and(r -> r.getType() == RepositoryType.MAVEN);
final Comparator<ManagedRepository> comparator = QUERY_HELPER.getComparator(orderBy, order);
int totalCount = Math.toIntExact(repos.stream().filter(queryFilter).count());
return PagedResult.of(totalCount, offset, limit, repos.stream().filter(queryFilter).sorted(comparator).map(mapper::reverseMap).skip(offset).limit(limit).collect(Collectors.toList()));
} catch (ArithmeticException e) {
log.error("Invalid number of repositories detected.");
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
}
}
use of org.apache.archiva.rest.api.v2.model.MavenManagedRepository 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.MavenManagedRepository in project archiva by apache.
the class MavenRepositoryMapperTest method updateWithNullValues.
@Test
void updateWithNullValues() {
MavenRepositoryMapper mapper = new MavenRepositoryMapper();
MavenManagedRepository repo = new MavenManagedRepository();
ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration();
repo.setId("repo01");
repo.setName("Repo 01");
repo.setDescription("This is repo 01");
repo.setLocation(null);
repo.setHasStagingRepository(true);
repo.setSchedulingDefinition("0,1,2 * * * *");
repo.setPackedIndexPath(null);
repo.setIndexPath(null);
repo.setIndex(true);
repo.setDeleteSnapshotsOfRelease(false);
repo.setBlocksRedeployments(false);
repo.setReleaseSchemes(Arrays.asList(ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name()));
repo.setCharacteristic(Repository.CHARACTERISTIC_MANAGED);
repo.setScanned(true);
repo.setRetentionPeriod(null);
repo.setRetentionCount(15);
repo.setSkipPackedIndexCreation(false);
repo.setStagingRepository(null);
mapper.update(repo, result);
assertNotNull(result);
assertEquals("repo01", result.getId());
assertEquals("Repo 01", result.getName());
assertEquals("This is repo 01", result.getDescription());
assertNotNull(result.getLocation());
assertTrue(result.isStageRepoNeeded());
assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
assertEquals("", result.getIndexDir());
assertEquals("", result.getPackedIndexDir());
assertFalse(result.isDeleteReleasedSnapshots());
assertFalse(result.isBlockRedeployments());
assertTrue(result.isSnapshots());
assertTrue(result.isReleases());
assertTrue(result.isScanned());
assertEquals(100, result.getRetentionPeriod());
assertEquals(15, result.getRetentionCount());
assertFalse(result.isSkipPackedIndexCreation());
}
use of org.apache.archiva.rest.api.v2.model.MavenManagedRepository in project archiva by apache.
the class MavenRepositoryMapperTest method update.
@Test
void update() {
MavenRepositoryMapper mapper = new MavenRepositoryMapper();
MavenManagedRepository repo = new MavenManagedRepository();
ManagedRepositoryConfiguration result = new ManagedRepositoryConfiguration();
repo.setId("repo01");
repo.setName("Repo 01");
repo.setDescription("This is repo 01");
repo.setLocation("/data/repo01");
repo.setHasStagingRepository(true);
repo.setSchedulingDefinition("0,1,2 * * * *");
repo.setPackedIndexPath(".index");
repo.setIndexPath(".indexer");
repo.setIndex(true);
repo.setDeleteSnapshotsOfRelease(false);
repo.setBlocksRedeployments(false);
repo.setReleaseSchemes(Arrays.asList(ReleaseScheme.RELEASE.name(), ReleaseScheme.SNAPSHOT.name()));
repo.setCharacteristic(Repository.CHARACTERISTIC_MANAGED);
repo.setScanned(true);
repo.setRetentionPeriod(Period.ofDays(10));
repo.setRetentionCount(15);
repo.setSkipPackedIndexCreation(false);
repo.setStagingRepository("stage-repo01");
mapper.update(repo, result);
assertNotNull(result);
assertEquals("repo01", result.getId());
assertEquals("Repo 01", result.getName());
assertEquals("This is repo 01", result.getDescription());
assertEquals("/data/repo01", result.getLocation());
assertTrue(result.isStageRepoNeeded());
assertEquals("0,1,2 * * * *", result.getRefreshCronExpression());
assertEquals(".indexer", result.getIndexDir());
assertEquals(".index", result.getPackedIndexDir());
assertFalse(result.isDeleteReleasedSnapshots());
assertFalse(result.isBlockRedeployments());
assertTrue(result.isSnapshots());
assertTrue(result.isReleases());
assertTrue(result.isScanned());
assertEquals(10, result.getRetentionPeriod());
assertEquals(15, result.getRetentionCount());
assertFalse(result.isSkipPackedIndexCreation());
}
Aggregations