Search in sources :

Example 6 with Architecture

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;
}
Also used : GetRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceMirrorResult) CreateRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.CreateRepositoryResult) CreateRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceRequest) RemoveRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorResult) LoggerFactory(org.slf4j.LoggerFactory) RepositorySourceExtraIdentifier(org.haiku.haikudepotserver.dataobjects.RepositorySourceExtraIdentifier) StringUtils(org.apache.commons.lang3.StringUtils) RepositoryService(org.haiku.haikudepotserver.repository.model.RepositoryService) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) UpdateRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceMirrorResult) org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror) PkgSearchSpecification(org.haiku.haikudepotserver.pkg.model.PkgSearchSpecification) SingleCollector(org.haiku.haikudepotserver.support.SingleCollector) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror) Set(java.util.Set) SearchRepositoriesResult(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesResult) UUID(java.util.UUID) GetRepositoriesResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositoriesResult) UpdateRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceResult) Collectors(java.util.stream.Collectors) GetRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceMirrorRequest) List(java.util.List) GetRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositoryRequest) UpdateRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositoryRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) Optional(java.util.Optional) Country(org.haiku.haikudepotserver.dataobjects.Country) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) UpdateRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositoryResult) TriggerImportRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.TriggerImportRepositoryRequest) ObjectContext(org.apache.cayenne.ObjectContext) Permission(org.haiku.haikudepotserver.security.model.Permission) ValidationException(org.haiku.haikudepotserver.api1.support.ValidationException) JobSnapshot(org.haiku.haikudepotserver.job.model.JobSnapshot) TriggerImportRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.TriggerImportRepositoryResult) BooleanUtils(org.apache.commons.lang3.BooleanUtils) GetRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult) PersistentObject(org.apache.cayenne.PersistentObject) CreateRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceResult) CollectionUtils(org.apache.commons.collections4.CollectionUtils) RemoveRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.RemoveRepositorySourceMirrorRequest) GetRepositoriesRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositoriesRequest) HashSet(java.util.HashSet) Strings(com.google.common.base.Strings) SetUtils(org.apache.commons.collections4.SetUtils) SearchRepositoriesRequest(org.haiku.haikudepotserver.api1.model.repository.SearchRepositoriesRequest) JobService(org.haiku.haikudepotserver.job.model.JobService) GetRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositoryResult) Logger(org.slf4j.Logger) UpdateRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceRequest) AutoJsonRpcServiceImpl(com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) AccessDeniedException(org.springframework.security.access.AccessDeniedException) PermissionEvaluator(org.springframework.security.access.PermissionEvaluator) CreateRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceMirrorRequest) RepositoryHpkrIngressJobSpecification(org.haiku.haikudepotserver.repository.model.RepositoryHpkrIngressJobSpecification) CreateRepositorySourceMirrorResult(org.haiku.haikudepotserver.api1.model.repository.CreateRepositorySourceMirrorResult) Component(org.springframework.stereotype.Component) CreateRepositoryRequest(org.haiku.haikudepotserver.api1.model.repository.CreateRepositoryRequest) ObjectId(org.apache.cayenne.ObjectId) UpdateRepositorySourceMirrorRequest(org.haiku.haikudepotserver.api1.model.repository.UpdateRepositorySourceMirrorRequest) Preconditions(com.google.common.base.Preconditions) RepositorySearchSpecification(org.haiku.haikudepotserver.repository.model.RepositorySearchSpecification) ValidationFailure(org.haiku.haikudepotserver.api1.support.ValidationFailure) ServerRuntime(org.apache.cayenne.configuration.server.ServerRuntime) Collections(java.util.Collections) GetRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) ObjectContext(org.apache.cayenne.ObjectContext) org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror) GetRepositoryResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositoryResult)

Example 7 with Architecture

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;
}
Also used : org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror) RepositorySourceMirror(org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) RepositorySource(org.haiku.haikudepotserver.dataobjects.RepositorySource) ObjectContext(org.apache.cayenne.ObjectContext) GetRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult)

Example 8 with Architecture

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);
    }
}
Also used : IncrementViewCounterRequest(org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterRequest) Repository(org.haiku.haikudepotserver.dataobjects.Repository) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) IncrementViewCounterResult(org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterResult) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 9 with Architecture

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();
    }
}
Also used : Repository(org.haiku.haikudepotserver.dataobjects.Repository) Architecture(org.haiku.haikudepotserver.dataobjects.Architecture) VersionCoordinates(org.haiku.haikudepotserver.support.VersionCoordinates) UpdatePkgVersionRequest(org.haiku.haikudepotserver.api1.model.pkg.UpdatePkgVersionRequest) PkgVersion(org.haiku.haikudepotserver.dataobjects.PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext) Pkg(org.haiku.haikudepotserver.dataobjects.Pkg) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

Architecture (org.haiku.haikudepotserver.dataobjects.Architecture)9 ObjectContext (org.apache.cayenne.ObjectContext)5 Repository (org.haiku.haikudepotserver.dataobjects.Repository)5 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)4 PkgVersion (org.haiku.haikudepotserver.dataobjects.PkgVersion)4 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)4 VersionCoordinates (org.haiku.haikudepotserver.support.VersionCoordinates)4 org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)2 GetRepositorySourceResult (org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult)2 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)2 RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror)2 Test (org.junit.jupiter.api.Test)2 Preconditions (com.google.common.base.Preconditions)1 Strings (com.google.common.base.Strings)1 AutoJsonRpcServiceImpl (com.googlecode.jsonrpc4j.spring.AutoJsonRpcServiceImpl)1 BufferedReader (java.io.BufferedReader)1