use of org.haiku.haikudepotserver.api1.model.repository.TriggerImportRepositoryRequest in project haikudepotserver by haiku.
the class RepositoryApiImpl method triggerImportRepository.
// note; no integration test for this one.
@Override
public TriggerImportRepositoryResult triggerImportRepository(TriggerImportRepositoryRequest triggerImportRepositoryRequest) {
Preconditions.checkNotNull(triggerImportRepositoryRequest);
Preconditions.checkState(!Strings.isNullOrEmpty(triggerImportRepositoryRequest.repositoryCode));
Preconditions.checkArgument(null == triggerImportRepositoryRequest.repositorySourceCodes || !triggerImportRepositoryRequest.repositorySourceCodes.isEmpty(), "bad repository sources");
final ObjectContext context = serverRuntime.newContext();
Optional<Repository> repositoryOptional = Repository.tryGetByCode(context, triggerImportRepositoryRequest.repositoryCode);
if (repositoryOptional.isEmpty()) {
throw new ObjectNotFoundException(Repository.class.getSimpleName(), triggerImportRepositoryRequest.repositoryCode);
}
Repository repository = repositoryOptional.get();
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repository, Permission.REPOSITORY_IMPORT)) {
throw new AccessDeniedException("attempt to trigger repository import for [" + repository + "]");
}
Set<RepositorySource> repositorySources = null;
if (null != triggerImportRepositoryRequest.repositorySourceCodes) {
repositorySources = new HashSet<>();
for (String repositorySourceCode : triggerImportRepositoryRequest.repositorySourceCodes) {
repositorySources.add(repository.getRepositorySources().stream().filter(rs -> rs.getCode().equals(repositorySourceCode)).collect(SingleCollector.optional()).orElseThrow(() -> new ObjectNotFoundException(RepositorySource.class.getSimpleName(), repositorySourceCode)));
}
}
jobService.submit(new RepositoryHpkrIngressJobSpecification(repository.getCode(), null == repositorySources ? null : repositorySources.stream().map(RepositorySource::getCode).collect(Collectors.toSet())), JobSnapshot.COALESCE_STATUSES_QUEUED);
return new TriggerImportRepositoryResult();
}
Aggregations