Search in sources :

Example 1 with IncrementViewCounterResult

use of org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterResult in project haikudepotserver by haiku.

the class PkgApiImpl method incrementViewCounter.

@Override
public IncrementViewCounterResult incrementViewCounter(IncrementViewCounterRequest request) {
    Preconditions.checkArgument(null != request, "the request object must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.name), "the package name must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.architectureCode), "the architecture must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository code must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.major), "the version major must be supplied");
    ObjectContext context = serverRuntime.newContext();
    VersionCoordinates versionCoordinates = new VersionCoordinates(request.major, request.minor, request.micro, request.preRelease, request.revision);
    PkgVersion pkgVersion = PkgVersion.getForPkg(context, Pkg.getByName(context, request.name), Repository.getByCode(context, request.repositoryCode), Architecture.getByCode(context, request.architectureCode), versionCoordinates).orElseThrow(() -> new ObjectNotFoundException(PkgVersion.class.getSimpleName(), versionCoordinates));
    incrementCounter(pkgVersion);
    return new IncrementViewCounterResult();
}
Also used : ObjectNotFoundException(org.haiku.haikudepotserver.api1.support.ObjectNotFoundException) org.haiku.haikudepotserver.dataobjects.auto._PkgVersion(org.haiku.haikudepotserver.dataobjects.auto._PkgVersion) ObjectContext(org.apache.cayenne.ObjectContext)

Example 2 with IncrementViewCounterResult

use of org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterResult 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)

Aggregations

ObjectContext (org.apache.cayenne.ObjectContext)2 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 IncrementViewCounterRequest (org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterRequest)1 IncrementViewCounterResult (org.haiku.haikudepotserver.api1.model.pkg.IncrementViewCounterResult)1 ObjectNotFoundException (org.haiku.haikudepotserver.api1.support.ObjectNotFoundException)1 Architecture (org.haiku.haikudepotserver.dataobjects.Architecture)1 Pkg (org.haiku.haikudepotserver.dataobjects.Pkg)1 PkgVersion (org.haiku.haikudepotserver.dataobjects.PkgVersion)1 Repository (org.haiku.haikudepotserver.dataobjects.Repository)1 org.haiku.haikudepotserver.dataobjects.auto._PkgVersion (org.haiku.haikudepotserver.dataobjects.auto._PkgVersion)1 VersionCoordinates (org.haiku.haikudepotserver.support.VersionCoordinates)1 Test (org.junit.jupiter.api.Test)1