use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class PkgApiImpl method removePkgScreenshot.
@Override
public RemovePkgScreenshotResult removePkgScreenshot(RemovePkgScreenshotRequest removePkgScreenshotRequest) {
Preconditions.checkNotNull(removePkgScreenshotRequest);
Preconditions.checkNotNull(removePkgScreenshotRequest.code);
final ObjectContext context = serverRuntime.newContext();
Optional<PkgScreenshot> screenshotOptional = PkgScreenshot.tryGetByCode(context, removePkgScreenshotRequest.code);
if (screenshotOptional.isEmpty()) {
throw new ObjectNotFoundException(PkgScreenshot.class.getSimpleName(), removePkgScreenshotRequest.code);
}
if (screenshotOptional.get().getPkgSupplement().getPkgs().stream().noneMatch(p -> permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), p, Permission.PKG_EDITSCREENSHOT))) {
throw new AccessDeniedException("unable to remove the package screenshot for package");
}
pkgScreenshotService.deleteScreenshot(context, screenshotOptional.get());
context.commitChanges();
LOGGER.info("did remove the screenshot {}", removePkgScreenshotRequest.code);
return new RemovePkgScreenshotResult();
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException 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.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class PkgApiImpl method getPkgVersionLocalizations.
@Override
public GetPkgVersionLocalizationsResult getPkgVersionLocalizations(GetPkgVersionLocalizationsRequest getPkgVersionLocalizationsRequest) {
Preconditions.checkNotNull(getPkgVersionLocalizationsRequest);
Preconditions.checkState(!Strings.isNullOrEmpty(getPkgVersionLocalizationsRequest.architectureCode));
Preconditions.checkState(!Strings.isNullOrEmpty(getPkgVersionLocalizationsRequest.pkgName));
Preconditions.checkNotNull(getPkgVersionLocalizationsRequest.naturalLanguageCodes);
Preconditions.checkArgument(!Strings.isNullOrEmpty(getPkgVersionLocalizationsRequest.repositoryCode), "the repository code must be supplied");
final ObjectContext context = serverRuntime.newContext();
Pkg pkg = getPkg(context, getPkgVersionLocalizationsRequest.pkgName);
Architecture architecture = getArchitecture(context, getPkgVersionLocalizationsRequest.architectureCode);
Repository repository = getRepository(context, getPkgVersionLocalizationsRequest.repositoryCode);
Optional<PkgVersion> pkgVersionOptional;
if (null == getPkgVersionLocalizationsRequest.major) {
pkgVersionOptional = pkgService.getLatestPkgVersionForPkg(context, pkg, repository, Collections.singletonList(architecture));
} else {
pkgVersionOptional = PkgVersion.getForPkg(context, pkg, repository, architecture, new VersionCoordinates(getPkgVersionLocalizationsRequest.major, getPkgVersionLocalizationsRequest.minor, getPkgVersionLocalizationsRequest.micro, getPkgVersionLocalizationsRequest.preRelease, getPkgVersionLocalizationsRequest.revision));
}
if (pkgVersionOptional.isEmpty() || !pkgVersionOptional.get().getActive()) {
throw new ObjectNotFoundException(PkgVersion.class.getSimpleName(), pkg.getName() + "/" + architecture.getCode());
}
GetPkgVersionLocalizationsResult result = new GetPkgVersionLocalizationsResult();
result.pkgVersionLocalizations = new ArrayList<>();
for (String naturalLanguageCode : getPkgVersionLocalizationsRequest.naturalLanguageCodes) {
Optional<PkgVersionLocalization> pkgVersionLocalizationOptional = pkgVersionOptional.get().getPkgVersionLocalization(naturalLanguageCode);
if (pkgVersionLocalizationOptional.isPresent()) {
org.haiku.haikudepotserver.api1.model.pkg.PkgVersionLocalization resultPkgVersionLocalization = new org.haiku.haikudepotserver.api1.model.pkg.PkgVersionLocalization();
resultPkgVersionLocalization.naturalLanguageCode = naturalLanguageCode;
resultPkgVersionLocalization.description = pkgVersionLocalizationOptional.get().getDescription().orElse(null);
resultPkgVersionLocalization.summary = pkgVersionLocalizationOptional.get().getSummary().orElse(null);
result.pkgVersionLocalizations.add(resultPkgVersionLocalization);
}
}
return result;
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class PkgJobApiImpl method queuePkgIconArchiveImportJob.
@Override
public QueuePkgIconArchiveImportJobResult queuePkgIconArchiveImportJob(QueuePkgIconArchiveImportJobRequest request) {
Preconditions.checkArgument(null != request, "the request must be supplied");
Preconditions.checkArgument(!Strings.isNullOrEmpty(request.inputDataGuid), "the input data must be identified by guid");
final ObjectContext context = serverRuntime.newContext();
Optional<User> user = tryObtainAuthenticatedUser(context);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.BULK_PKGICONIMPORTARCHIVE)) {
throw new AccessDeniedException("attempt to import package icons, but was not authorized");
}
// now check that the data is present.
jobService.tryGetData(request.inputDataGuid).orElseThrow(() -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid));
// setup and go
PkgIconImportArchiveJobSpecification spec = new PkgIconImportArchiveJobSpecification();
spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null));
spec.setInputDataGuid(request.inputDataGuid);
return new QueuePkgIconArchiveImportJobResult(jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE));
}
use of org.haiku.haikudepotserver.api1.support.ObjectNotFoundException in project haikudepotserver by haiku.
the class PkgJobApiImpl method queuePkgScreenshotArchiveImportJob.
@Override
public QueuePkgScreenshotArchiveImportJobResult queuePkgScreenshotArchiveImportJob(QueuePkgScreenshotArchiveImportJobRequest request) {
Preconditions.checkArgument(null != request, "the request must be supplied");
Preconditions.checkArgument(StringUtils.isNotBlank(request.inputDataGuid), "the data guid must be supplied");
Preconditions.checkArgument(null != request.importStrategy, "the import strategy must be supplied");
final ObjectContext context = serverRuntime.newContext();
Optional<User> user = tryObtainAuthenticatedUser(context);
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.BULK_PKGSCREENSHOTIMPORTARCHIVE)) {
throw new AccessDeniedException("attempt to import package screenshots, but was not authorized");
}
// now check that the data is present.
jobService.tryGetData(request.inputDataGuid).orElseThrow(() -> new ObjectNotFoundException(JobData.class.getSimpleName(), request.inputDataGuid));
// setup and go
PkgScreenshotImportArchiveJobSpecification spec = new PkgScreenshotImportArchiveJobSpecification();
spec.setOwnerUserNickname(user.map(_User::getNickname).orElse(null));
spec.setInputDataGuid(request.inputDataGuid);
spec.setImportStrategy(PkgScreenshotImportArchiveJobSpecification.ImportStrategy.valueOf(request.importStrategy.name()));
return new QueuePkgScreenshotArchiveImportJobResult(jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_NONE));
}
Aggregations