use of org.haiku.haikudepotserver.dataobjects.Architecture 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.dataobjects.Architecture 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.dataobjects.Architecture in project haikudepotserver by haiku.
the class PkgApiIT method testIncrementViewCounter.
@Test
public void testIncrementViewCounter() {
integrationTestSupportService.createStandardTestData();
IncrementViewCounterRequest request = new IncrementViewCounterRequest();
request.major = "1";
request.micro = "2";
request.revision = 3;
request.name = "pkg1";
request.architectureCode = "x86_64";
request.repositoryCode = "testrepo";
// ------------------------------------
IncrementViewCounterResult result = pkgApi.incrementViewCounter(request);
// ------------------------------------
Assertions.assertThat(result).isNotNull();
{
ObjectContext context = serverRuntime.newContext();
Pkg pkg1 = Pkg.getByName(context, "pkg1");
Repository repository = Repository.getByCode(context, "testrepo");
Architecture architecture = Architecture.getByCode(context, "x86_64");
PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg1, repository, architecture, new VersionCoordinates("1", null, "2", null, 3)).get();
Assertions.assertThat(pkgVersion.getViewCounter()).isEqualTo(1L);
}
}
use of org.haiku.haikudepotserver.dataobjects.Architecture in project haikudepotserver by haiku.
the class PkgApiIT method updatePkgVersion_deactivate.
@Test
public void updatePkgVersion_deactivate() {
integrationTestSupportService.createStandardTestData();
setAuthenticatedUserToRoot();
UpdatePkgVersionRequest request = new UpdatePkgVersionRequest();
request.pkgName = "pkg1";
request.repositoryCode = "testrepo";
request.architectureCode = "x86_64";
request.major = "1";
request.micro = "2";
request.revision = 3;
request.filter = Collections.singletonList(UpdatePkgVersionRequest.Filter.ACTIVE);
request.active = false;
// ------------------------------------
pkgApi.updatePkgVersion(request);
// ------------------------------------
{
ObjectContext context = serverRuntime.newContext();
Pkg pkg1 = Pkg.getByName(context, "pkg1");
Repository repository = Repository.getByCode(context, "testrepo");
Architecture architecture = Architecture.getByCode(context, "x86_64");
PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg1, repository, architecture, new VersionCoordinates("1", null, "2", null, 3)).get();
Assertions.assertThat(pkgVersion.getActive()).isFalse();
}
}
Aggregations