use of org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceRequest in project haikudepotserver by haiku.
the class RepositoryApiImpl method getRepositorySource.
@Override
public GetRepositorySourceResult getRepositorySource(GetRepositorySourceRequest request) {
Preconditions.checkArgument(null != request);
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.code));
final ObjectContext context = serverRuntime.newContext();
Optional<RepositorySource> repositorySourceOptional = RepositorySource.tryGetByCode(context, request.code);
if (repositorySourceOptional.isEmpty()) {
throw new ObjectNotFoundException(RepositorySource.class.getSimpleName(), request.code);
}
RepositorySource repositorySource = repositorySourceOptional.get();
GetRepositorySourceResult result = new GetRepositorySourceResult();
result.active = repositorySource.getActive();
result.code = repositorySource.getCode();
result.repositoryCode = repositorySource.getRepository().getCode();
result.identifier = repositorySource.getIdentifier();
result.architectureCode = Optional.ofNullable(repositorySource.getArchitecture()).map(Architecture::getCode).orElse(null);
if (null != repositorySource.getLastImportTimestamp()) {
result.lastImportTimestamp = repositorySource.getLastImportTimestamp().getTime();
}
result.extraIdentifiers = repositorySource.getExtraIdentifiers();
result.repositorySourceMirrors = repositorySource.getRepositorySourceMirrors().stream().filter(m -> m.getActive() || BooleanUtils.isTrue(request.includeInactiveRepositorySourceMirrors)).sorted().map(rsm -> {
GetRepositorySourceResult.RepositorySourceMirror mirror = new GetRepositorySourceResult.RepositorySourceMirror();
mirror.active = rsm.getActive();
mirror.baseUrl = rsm.getBaseUrl();
mirror.countryCode = rsm.getCountry().getCode();
mirror.isPrimary = rsm.getIsPrimary();
mirror.code = rsm.getCode();
return mirror;
}).collect(Collectors.toList());
if (permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repositorySource.getRepository(), Permission.REPOSITORY_EDIT)) {
result.forcedInternalBaseUrl = repositorySourceOptional.get().getForcedInternalBaseUrl();
}
return result;
}
use of org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceRequest in project haikudepotserver by haiku.
the class RepositoryApiIT method testGetRepositorySource.
@Test
public void testGetRepositorySource() {
IntegrationTestSupportService.StandardTestData data = integrationTestSupportService.createStandardTestData();
GetRepositorySourceRequest request = new GetRepositorySourceRequest();
request.code = data.pkg1Version1x86_64.getRepositorySource().getCode();
// ------------------------------------
GetRepositorySourceResult result = repositoryApi.getRepositorySource(request);
// ------------------------------------
Assertions.assertThat(result.active).isTrue();
Assertions.assertThat(result.code).isEqualTo("testreposrc_xyz");
Assertions.assertThat(result.repositoryCode).isEqualTo("testrepo");
Assertions.assertThat(result.identifier).isEqualTo("http://www.example.com/test/identifier/url");
Assertions.assertThat(result.repositorySourceMirrors.size()).isEqualTo(2);
Assertions.assertThat(result.extraIdentifiers).containsExactly("example:haiku:identifier");
Assertions.assertThat(result.architectureCode).isEqualTo("x86_64");
GetRepositorySourceResult.RepositorySourceMirror mirror0 = result.repositorySourceMirrors.get(0);
GetRepositorySourceResult.RepositorySourceMirror mirror1 = result.repositorySourceMirrors.get(1);
Assertions.assertThat(mirror0.code).isEqualTo("testreposrc_xyz_m_pri");
Assertions.assertThat(mirror0.baseUrl).isEqualTo("file:///tmp/repository");
Assertions.assertThat(mirror1.code).isEqualTo("testreposrc_xyz_m_notpri");
Assertions.assertThat(mirror1.baseUrl).isEqualTo("file://not-found/on-disk");
}
Aggregations