use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.
the class DefaultRepositoryService method scheduleDownloadRemoteIndex.
@Override
public Response scheduleDownloadRemoteIndex(String repositoryId, boolean immediately, boolean full, UriInfo uriInfo) throws ArchivaRestServiceException {
boolean immediateSet = RestUtil.isFlagSet(uriInfo, "immediate");
boolean fullSet = RestUtil.isFlagSet(uriInfo, "full");
RemoteRepository repo = repositoryRegistry.getRemoteRepository(repositoryId);
if (repo == null) {
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_REMOTE_NOT_FOUND, repositoryId), 404);
}
try {
downloadRemoteIndexScheduler.scheduleDownloadRemote(repositoryId, immediateSet, fullSet);
return Response.ok().build();
} catch (DownloadRemoteIndexException e) {
log.error("Could not schedule index download for repository {}: {}", repositoryId, e.getMessage(), e);
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.REPOSITORY_REMOTE_INDEX_DOWNLOAD_FAILED, e.getMessage()));
}
}
use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.
the class DefaultRepositoryService method getRepositories.
@Override
public PagedResult<Repository> getRepositories(String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order, String localeString) throws ArchivaRestServiceException {
final Locale locale = StringUtils.isNotEmpty(localeString) ? Locale.forLanguageTag(localeString) : Locale.getDefault();
boolean isAscending = QUERY_HELPER.isAscending(order);
Predicate<org.apache.archiva.repository.Repository> filter = QUERY_HELPER.getQueryFilter(searchTerm);
Comparator<org.apache.archiva.repository.Repository> comparator = QUERY_HELPER.getComparator(orderBy, isAscending);
try {
int totalCount = Math.toIntExact(repositoryRegistry.getRepositories().stream().filter(filter).count());
return new PagedResult<>(totalCount, offset, limit, repositoryRegistry.getRepositories().stream().filter(filter).skip(offset).limit(limit).sorted(comparator).map(repo -> Repository.of(repo, locale)).collect(Collectors.toList()));
} catch (ArithmeticException e) {
log.error("Invalid integer conversion for totalCount");
throw new ArchivaRestServiceException(ErrorMessage.of(ErrorKeys.INVALID_RESULT_SET_ERROR));
}
}
use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.
the class MavenRepositoryMapperTest method reverseMap.
@Test
void reverseMap() throws IOException, URISyntaxException, UnsupportedURIException {
MavenRepositoryMapper mapper = new MavenRepositoryMapper();
Path tmpDir = Files.createTempDirectory("mapper-test");
FilesystemStorage fsStorage = new FilesystemStorage(tmpDir, new DefaultFileLockManager());
EditableManagedRepository repository = new BasicManagedRepository(Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage);
repository.setDescription(Locale.getDefault(), "This is repo 02");
repository.setBlocksRedeployment(false);
repository.setLocation(new URI("test-path"));
repository.setScanned(true);
repository.setLayout("maven2");
repository.setSchedulingDefinition("* 3,5,10 * * *");
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class);
icf.setIndexPath(new URI(".indexer"));
icf.setPackedIndexPath(new URI(".index"));
icf.setSkipPackedIndexCreation(false);
ArtifactCleanupFeature acf = repository.getFeature(ArtifactCleanupFeature.class);
acf.setDeleteReleasedSnapshots(false);
acf.setRetentionPeriod(Period.ofDays(5));
acf.setRetentionCount(17);
StagingRepositoryFeature srf = repository.getFeature(StagingRepositoryFeature.class);
srf.setStageRepoNeeded(false);
MavenManagedRepository result = mapper.reverseMap(repository);
assertEquals("repo02", result.getId());
assertEquals("Repo 02", result.getName());
assertEquals("This is repo 02", result.getDescription());
assertFalse(result.isBlocksRedeployments());
assertEquals("test-path", result.getLocation());
assertTrue(result.isScanned());
assertEquals("maven2", result.getLayout());
assertEquals("* 3,5,10 * * *", result.getSchedulingDefinition());
assertEquals(".indexer", result.getIndexPath());
assertEquals(".index", result.getPackedIndexPath());
assertFalse(result.isSkipPackedIndexCreation());
assertFalse(result.isDeleteSnapshotsOfRelease());
assertEquals(Period.ofDays(5), result.getRetentionPeriod());
assertEquals(17, result.getRetentionCount());
assertFalse(result.hasStagingRepository());
}
use of org.apache.archiva.rest.api.v2.model.Repository in project archiva by apache.
the class MavenRepositoryMapperTest method reverseUpdate.
@Test
void reverseUpdate() throws IOException, URISyntaxException, UnsupportedURIException {
MavenRepositoryMapper mapper = new MavenRepositoryMapper();
MavenManagedRepository result = new MavenManagedRepository();
Path tmpDir = Files.createTempDirectory("mapper-test");
FilesystemStorage fsStorage = new FilesystemStorage(tmpDir, new DefaultFileLockManager());
EditableManagedRepository repository = new BasicManagedRepository(Locale.getDefault(), RepositoryType.MAVEN, "repo02", "Repo 02", fsStorage);
repository.setDescription(Locale.getDefault(), "This is repo 02");
repository.setBlocksRedeployment(false);
repository.setLocation(new URI("test-path"));
repository.setScanned(true);
repository.setLayout("maven2");
repository.setSchedulingDefinition("* 3,5,10 * * *");
IndexCreationFeature icf = repository.getFeature(IndexCreationFeature.class);
icf.setIndexPath(new URI(".indexer"));
icf.setPackedIndexPath(new URI(".index"));
icf.setSkipPackedIndexCreation(false);
ArtifactCleanupFeature acf = repository.getFeature(ArtifactCleanupFeature.class);
acf.setDeleteReleasedSnapshots(false);
acf.setRetentionPeriod(Period.ofDays(5));
acf.setRetentionCount(17);
StagingRepositoryFeature srf = repository.getFeature(StagingRepositoryFeature.class);
srf.setStageRepoNeeded(false);
mapper.reverseUpdate(repository, result);
assertEquals("repo02", result.getId());
assertEquals("Repo 02", result.getName());
assertEquals("This is repo 02", result.getDescription());
assertFalse(result.isBlocksRedeployments());
assertEquals("test-path", result.getLocation());
assertTrue(result.isScanned());
assertEquals("maven2", result.getLayout());
assertEquals("* 3,5,10 * * *", result.getSchedulingDefinition());
assertEquals(".indexer", result.getIndexPath());
assertEquals(".index", result.getPackedIndexPath());
assertFalse(result.isSkipPackedIndexCreation());
assertFalse(result.isDeleteSnapshotsOfRelease());
assertEquals(Period.ofDays(5), result.getRetentionPeriod());
assertEquals(17, result.getRetentionCount());
assertFalse(result.hasStagingRepository());
}
use of org.apache.archiva.rest.api.v2.model.Repository 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()));
}
}
Aggregations