use of org.haiku.haikudepotserver.api1.model.repository.GetRepositoryResult in project haikudepotserver by haiku.
the class RepositoryApiImpl method getRepository.
@Override
public GetRepositoryResult getRepository(GetRepositoryRequest getRepositoryRequest) {
Preconditions.checkNotNull(getRepositoryRequest);
Preconditions.checkState(!Strings.isNullOrEmpty(getRepositoryRequest.code));
final ObjectContext context = serverRuntime.newContext();
final Repository repository = getRepositoryOrThrow(context, getRepositoryRequest.code);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), repository, Permission.REPOSITORY_VIEW)) {
throw new AccessDeniedException("unable to view repository [" + repository + "]");
}
GetRepositoryResult result = new GetRepositoryResult();
result.active = repository.getActive();
result.code = repository.getCode();
result.name = repository.getName();
result.createTimestamp = repository.getCreateTimestamp().getTime();
result.modifyTimestamp = repository.getModifyTimestamp().getTime();
result.informationUrl = repository.getInformationUrl();
result.hasPassword = StringUtils.isNotBlank(repository.getPasswordHash());
result.repositorySources = repository.getRepositorySources().stream().filter(rs -> rs.getActive() || (null != getRepositoryRequest.includeInactiveRepositorySources && getRepositoryRequest.includeInactiveRepositorySources)).map(rs -> {
GetRepositoryResult.RepositorySource resultRs = new GetRepositoryResult.RepositorySource();
resultRs.active = rs.getActive();
resultRs.code = rs.getCode();
resultRs.url = rs.tryGetPrimaryMirror().map(_RepositorySourceMirror::getBaseUrl).orElse(null);
resultRs.identifier = rs.getIdentifier();
resultRs.architectureCode = Optional.ofNullable(rs.getArchitecture()).map(Architecture::getCode).orElse(null);
if (null != rs.getLastImportTimestamp()) {
resultRs.lastImportTimestamp = rs.getLastImportTimestamp().getTime();
}
return resultRs;
}).collect(Collectors.toList());
return result;
}
use of org.haiku.haikudepotserver.api1.model.repository.GetRepositoryResult in project haikudepotserver by haiku.
the class RepositoryApiIT method getRepositoryTest.
@Test
public void getRepositoryTest() {
integrationTestSupportService.createStandardTestData();
GetRepositoryRequest request = new GetRepositoryRequest();
request.code = "testrepo";
// ------------------------------------
GetRepositoryResult result = repositoryApi.getRepository(request);
// ------------------------------------
Assertions.assertThat(result.active).isTrue();
Assertions.assertThat(result.code).isEqualTo("testrepo");
Assertions.assertThat(result.informationUrl).isEqualTo("http://example1.haiku.org/");
Assertions.assertThat(result.repositorySources.size()).isEqualTo(1);
GetRepositoryResult.RepositorySource repositorySource = result.repositorySources.get(0);
Assertions.assertThat(repositorySource.code).isEqualTo("testreposrc_xyz");
Assertions.assertThat(repositorySource.active).isTrue();
Assertions.assertThat(repositorySource.url).startsWith("file:///");
Assertions.assertThat(repositorySource.architectureCode).isEqualTo("x86_64");
}
Aggregations