Search in sources :

Example 1 with UpdatePkgVersionRequest

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

the class PkgApiImpl method updatePkgVersion.

@Override
public UpdatePkgVersionResult updatePkgVersion(UpdatePkgVersionRequest request) {
    Preconditions.checkArgument(null != request, "the request object must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.pkgName), "the package name must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.repositoryCode), "the repository code must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.architectureCode), "the architecture code must be supplied");
    Preconditions.checkArgument(!Strings.isNullOrEmpty(request.major), "the version major must be supplied");
    ObjectContext context = serverRuntime.newContext();
    Pkg pkg = getPkg(context, request.pkgName);
    if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), pkg, Permission.PKG_EDITVERSION)) {
        throw new AccessDeniedException("unable to update the package version for package [" + pkg + "]");
    }
    PkgVersion pkgVersion = PkgVersion.getForPkg(context, pkg, getRepository(context, request.repositoryCode), getArchitecture(context, request.architectureCode), new VersionCoordinates(request.major, request.minor, request.micro, request.preRelease, request.revision)).orElseThrow(() -> new ObjectNotFoundException(PkgVersion.class.getSimpleName(), null));
    for (UpdatePkgVersionRequest.Filter filter : request.filter) {
        switch(filter) {
            case ACTIVE:
                LOGGER.info("will update the package version active flag to {} for {}", request.active, pkgVersion.toString());
                pkgVersion.setActive(request.active);
                pkgService.adjustLatest(context, pkgVersion.getPkg(), pkgVersion.getArchitecture());
                break;
        }
    }
    context.commitChanges();
    return new UpdatePkgVersionResult();
}
Also used : AccessDeniedException(org.springframework.security.access.AccessDeniedException) 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 UpdatePkgVersionRequest

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

ObjectContext (org.apache.cayenne.ObjectContext)2 AbstractIntegrationTest (org.haiku.haikudepotserver.AbstractIntegrationTest)1 UpdatePkgVersionRequest (org.haiku.haikudepotserver.api1.model.pkg.UpdatePkgVersionRequest)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 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1