Search in sources :

Example 1 with GetRepositorySourceResult

use of org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult 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 2 with GetRepositorySourceResult

use of org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult 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");
}
Also used : GetRepositorySourceResult(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult) GetRepositorySourceRequest(org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceRequest) IntegrationTestSupportService(org.haiku.haikudepotserver.IntegrationTestSupportService) AbstractIntegrationTest(org.haiku.haikudepotserver.AbstractIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

GetRepositorySourceResult (org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceResult)2 ObjectContext (org.apache.cayenne.ObjectContext)1 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 IntegrationTestSupportService (org.haiku.haikudepotserver.IntegrationTestSupportService)1 GetRepositorySourceRequest (org.haiku.haikudepotserver.api1.model.repository.GetRepositorySourceRequest)1 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)1 Architecture (org.haiku.haikudepotserver.dataobjects.Architecture)1 RepositorySource (org.haiku.haikudepotserver.dataobjects.RepositorySource)1 RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.RepositorySourceMirror)1 org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror (org.haiku.haikudepotserver.dataobjects.auto._RepositorySourceMirror)1 Test (org.junit.jupiter.api.Test)1