use of org.haiku.haikudepotserver.job.model.AbstractJobSpecification in project haikudepotserver by haiku.
the class PkgJobApiImpl method queueSimplePkgJob.
private <R extends AbstractQueueJobResult> R queueSimplePkgJob(Class<R> resultClass, Class<? extends AbstractJobSpecification> jobSpecificationClass, Permission permission) {
final ObjectContext context = serverRuntime.newContext();
Optional<User> user = tryObtainAuthenticatedUser(context);
if (user.isEmpty()) {
throw new AccessDeniedException("attempt to queue [" + jobSpecificationClass.getSimpleName() + "] without a user");
}
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, permission)) {
throw new AccessDeniedException("attempt to queue [" + jobSpecificationClass.getSimpleName() + "] without sufficient authorization");
}
AbstractJobSpecification spec;
try {
spec = jobSpecificationClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("unable to create the job specification for class; " + jobSpecificationClass.getSimpleName(), e);
}
spec.setOwnerUserNickname(user.get().getNickname());
R result;
try {
result = resultClass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException("unable to create the result; " + resultClass.getSimpleName(), e);
}
result.guid = jobService.submit(spec, JobSnapshot.COALESCE_STATUSES_QUEUED_STARTED);
return result;
}
Aggregations