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();
}
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();
}
}
Aggregations