use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.
the class JobApiIT method testSearchJobs_startedOnly.
@Test
public void testSearchJobs_startedOnly() {
setAuthenticatedUserToRoot();
SearchJobsRequest request = new SearchJobsRequest();
request.statuses = EnumSet.of(JobStatus.STARTED);
// ------------------------------------
SearchJobsResult result = jobApi.searchJobs(request);
// ------------------------------------
Assertions.assertThat(result.items.size()).isEqualTo(1);
SearchJobsResult.Job job = result.items.get(0);
Assertions.assertThat(job.guid).isEqualTo("started");
Assertions.assertThat(job.queuedTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_FEB.toEpochMilli());
Assertions.assertThat(job.startTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_MAR.toEpochMilli());
Assertions.assertThat(job.finishTimestamp).isNull();
Assertions.assertThat(job.ownerUserNickname).isNull();
Assertions.assertThat(job.jobStatus).isEqualTo(JobStatus.STARTED);
}
use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.
the class JobApiIT method testSearchJobs_userOnly.
@Test
public void testSearchJobs_userOnly() {
{
ObjectContext context = serverRuntime.newContext();
// language is english
User user = integrationTestSupportService.createBasicUser(context, "testuser", "yUe4o2Nwe009");
integrationTestSupportService.agreeToUserUsageConditions(context, user);
setAuthenticatedUser("testuser");
}
SearchJobsRequest request = new SearchJobsRequest();
request.ownerUserNickname = "testuser";
// ------------------------------------
SearchJobsResult result = jobApi.searchJobs(request);
// ------------------------------------
Assertions.assertThat(result.items.size()).isEqualTo(1);
SearchJobsResult.Job job = result.items.get(0);
Assertions.assertThat(job.guid).isEqualTo("finished");
Assertions.assertThat(job.queuedTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_APR.toEpochMilli());
Assertions.assertThat(job.startTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_JUN.toEpochMilli());
Assertions.assertThat(job.finishTimestamp.longValue()).isEqualTo(TestJobServiceImpl.DT_1976_JUL.toEpochMilli());
Assertions.assertThat(job.ownerUserNickname).isEqualTo("testuser");
Assertions.assertThat(job.jobStatus).isEqualTo(JobStatus.FINISHED);
}
use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.
the class JobApiIT method testSearchJobs_all.
/**
* <p>This test will find some data because it is sourced from {@link TestJobServiceImpl}.</p>
*/
@Test
public void testSearchJobs_all() {
setAuthenticatedUserToRoot();
// ------------------------------------
SearchJobsResult result = jobApi.searchJobs(new SearchJobsRequest());
// ------------------------------------
Assertions.assertThat(result.items.size()).isEqualTo(3);
}
use of org.haiku.haikudepotserver.api1.model.job.SearchJobsResult in project haikudepotserver by haiku.
the class JobApiImpl method searchJobs.
@Override
public SearchJobsResult searchJobs(SearchJobsRequest request) {
Preconditions.checkArgument(null != request);
final SearchJobsResult result = new SearchJobsResult();
final ObjectContext context = serverRuntime.newContext();
User ownerUser = null;
if (Strings.isNullOrEmpty(request.ownerUserNickname)) {
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), null, Permission.JOBS_VIEW)) {
throw new AccessDeniedException("attempt to access jobs view");
}
} else {
ownerUser = User.tryGetByNickname(context, request.ownerUserNickname).orElseThrow(() -> new ObjectNotFoundException(User.class.getSimpleName(), request.ownerUserNickname));
if (!permissionEvaluator.hasPermission(SecurityContextHolder.getContext().getAuthentication(), ownerUser, Permission.USER_VIEWJOBS)) {
throw new AccessDeniedException("attempt to access jobs view for [" + ownerUser + "]");
}
}
if (null != request.statuses && request.statuses.isEmpty()) {
result.items = Collections.emptyList();
result.total = 0L;
} else {
Set<JobSnapshot.Status> statuses = null;
if (null != request.statuses) {
statuses = request.statuses.stream().map(s -> JobSnapshot.Status.valueOf(s.name())).collect(Collectors.toSet());
}
result.total = (long) jobService.totalJobs(ownerUser, statuses);
result.items = jobService.findJobs(ownerUser, statuses, null == request.offset ? 0 : request.offset, null == request.limit ? Integer.MAX_VALUE : request.limit).stream().map(js -> {
SearchJobsResult.Job resultJob = new SearchJobsResult.Job();
resultJob.guid = js.getGuid();
resultJob.jobStatus = JobStatus.valueOf(js.getStatus().name());
resultJob.jobTypeCode = js.getJobTypeCode();
resultJob.ownerUserNickname = js.getOwnerUserNickname();
resultJob.startTimestamp = null == js.getStartTimestamp() ? null : js.getStartTimestamp().getTime();
resultJob.finishTimestamp = null == js.getFinishTimestamp() ? null : js.getFinishTimestamp().getTime();
resultJob.queuedTimestamp = null == js.getQueuedTimestamp() ? null : js.getQueuedTimestamp().getTime();
resultJob.failTimestamp = null == js.getFailTimestamp() ? null : js.getFailTimestamp().getTime();
resultJob.cancelTimestamp = null == js.getCancelTimestamp() ? null : js.getCancelTimestamp().getTime();
resultJob.progressPercent = js.getProgressPercent();
return resultJob;
}).collect(Collectors.toList());
LOGGER.info("search for jobs found {} results", result.items.size());
}
return result;
}
Aggregations