use of org.haiku.haikudepotserver.userrating.model.UserRatingSpreadsheetJobSpecification in project haikudepotserver by haiku.
the class UserRatingJobApiImpl method queueUserRatingSpreadsheetJob.
@Override
public QueueUserRatingSpreadsheetJobResult queueUserRatingSpreadsheetJob(QueueUserRatingSpreadsheetJobRequest request) {
Preconditions.checkArgument(null != request);
Preconditions.checkArgument(Strings.isNullOrEmpty(request.pkgName) || Strings.isNullOrEmpty(request.userNickname), "the user nickname or pkg name can be supplied, but not both");
final ObjectContext context = serverRuntime.newContext();
User user = obtainAuthenticatedUser(context);
UserRatingSpreadsheetJobSpecification spec = new UserRatingSpreadsheetJobSpecification();
if (!Strings.isNullOrEmpty(request.repositoryCode)) {
spec.setRepositoryCode(getRepository(context, request.repositoryCode).getCode());
}
if (!Strings.isNullOrEmpty(request.userNickname)) {
Optional<User> requestUserOptional = User.tryGetByNickname(context, request.userNickname);
if (requestUserOptional.isEmpty()) {
throw new AccessDeniedException("attempt to produce user rating report for user [" + request.userNickname + "], but that user does not exist -- not allowed");
}
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), requestUserOptional.get(), Permission.BULK_USERRATINGSPREADSHEETREPORT_USER)) {
throw new AccessDeniedException("attempt to access a user rating report for user [" + request.userNickname + "], but this was disallowed");
}
spec.setUserNickname(request.userNickname);
} else {
if (!Strings.isNullOrEmpty(request.pkgName)) {
Optional<Pkg> requestPkgOptional = Pkg.tryGetByName(context, request.pkgName);
if (requestPkgOptional.isEmpty()) {
throw new AccessDeniedException("attempt to produce user rating report for pkg [" + request.pkgName + "], but that pkg does not exist -- not allowed");
}
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), requestPkgOptional.get(), Permission.BULK_USERRATINGSPREADSHEETREPORT_PKG)) {
throw new AccessDeniedException("attempt to access a user rating report for pkg [" + request.pkgName + "], but this was disallowed");
}
spec.setPkgName(request.pkgName);
} else {
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.BULK_USERRATINGSPREADSHEETREPORT_ALL)) {
throw new AccessDeniedException("attempt to access a user rating report, but was unauthorized");
}
}
}
spec.setOwnerUserNickname(user.getNickname());
return new QueueUserRatingSpreadsheetJobResult(jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED));
}
Aggregations